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 ( |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 18 | "fmt" |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 19 | "path/filepath" |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 20 | "strings" |
| 21 | |
Jeongik Cha | 6bd33c1 | 2019-06-25 16:26:18 +0900 | [diff] [blame] | 22 | "github.com/google/blueprint/proptools" |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 23 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 24 | "android/soong/android" |
| 25 | "android/soong/java/config" |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 26 | ) |
| 27 | |
| 28 | func init() { |
Paul Duffin | 884363e | 2019-12-19 10:21:09 +0000 | [diff] [blame] | 29 | RegisterDocsBuildComponents(android.InitRegistrationContext) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 30 | } |
| 31 | |
Paul Duffin | 884363e | 2019-12-19 10:21:09 +0000 | [diff] [blame] | 32 | func RegisterDocsBuildComponents(ctx android.RegistrationContext) { |
| 33 | ctx.RegisterModuleType("doc_defaults", DocDefaultsFactory) |
| 34 | |
| 35 | ctx.RegisterModuleType("droiddoc", DroiddocFactory) |
| 36 | ctx.RegisterModuleType("droiddoc_host", DroiddocHostFactory) |
| 37 | ctx.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory) |
| 38 | ctx.RegisterModuleType("javadoc", JavadocFactory) |
| 39 | ctx.RegisterModuleType("javadoc_host", JavadocHostFactory) |
| 40 | } |
| 41 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 42 | type JavadocProperties struct { |
| 43 | // list of source files used to compile the Java module. May be .java, .logtags, .proto, |
| 44 | // or .aidl files. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 45 | Srcs []string `android:"path,arch_variant"` |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 46 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 47 | // list of source files that should not be used to build the Java module. |
| 48 | // This is most useful in the arch/multilib variants to remove non-common files |
| 49 | // filegroup or genrule can be included within this property. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 50 | Exclude_srcs []string `android:"path,arch_variant"` |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 51 | |
Jiyong Park | c6ddccf | 2019-09-13 20:56:14 +0900 | [diff] [blame] | 52 | // list of package names that should actually be used. If this property is left unspecified, |
| 53 | // all the sources from the srcs property is used. |
| 54 | Filter_packages []string |
| 55 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 56 | // list of java libraries that will be in the classpath. |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 57 | Libs []string `android:"arch_variant"` |
| 58 | |
| 59 | // 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] | 60 | Installable *bool |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 61 | |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 62 | // if not blank, set to the version of the sdk to compile against. |
| 63 | // Defaults to compiling against the current platform. |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 64 | Sdk_version *string `android:"arch_variant"` |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 65 | |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 66 | // When targeting 1.9 and above, override the modules to use with --system, |
| 67 | // otherwise provides defaults libraries to add to the bootclasspath. |
| 68 | // Defaults to "none" |
| 69 | System_modules *string |
| 70 | |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 71 | Aidl struct { |
| 72 | // Top level directories to pass to aidl tool |
| 73 | Include_dirs []string |
| 74 | |
| 75 | // Directories rooted at the Android.bp file to pass to aidl tool |
| 76 | Local_include_dirs []string |
| 77 | } |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 78 | |
| 79 | // If not blank, set the java version passed to javadoc as -source |
| 80 | Java_version *string |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 81 | |
| 82 | // local files that are used within user customized droiddoc options. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 83 | Arg_files []string `android:"path"` |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 84 | |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 85 | // user customized droiddoc args. Deprecated, use flags instead. |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 86 | // Available variables for substitution: |
| 87 | // |
| 88 | // $(location <label>): the path to the arg_files with name <label> |
Colin Cross | e4a0584 | 2019-05-28 10:17:14 -0700 | [diff] [blame] | 89 | // $$: a literal $ |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 90 | Args *string |
| 91 | |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 92 | // user customized droiddoc args. Not compatible with property args. |
| 93 | // Available variables for substitution: |
| 94 | // |
| 95 | // $(location <label>): the path to the arg_files with name <label> |
| 96 | // $$: a literal $ |
| 97 | Flags []string |
| 98 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 99 | // names of the output files used in args that will be generated |
| 100 | Out []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 101 | } |
| 102 | |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 103 | type ApiToCheck struct { |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 104 | // path to the API txt file that the new API extracted from source code is checked |
| 105 | // against. The path can be local to the module or from other module (via :module syntax). |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 106 | Api_file *string `android:"path"` |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 107 | |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 108 | // path to the API txt file that the new @removed API extractd from source code is |
| 109 | // checked against. The path can be local to the module or from other module (via |
| 110 | // :module syntax). |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 111 | Removed_api_file *string `android:"path"` |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 112 | |
Adrian Roos | 14f75a9 | 2019-08-12 17:54:09 +0200 | [diff] [blame] | 113 | // If not blank, path to the baseline txt file for approved API check violations. |
| 114 | Baseline_file *string `android:"path"` |
| 115 | |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 116 | // Arguments to the apicheck tool. |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 117 | Args *string |
| 118 | } |
| 119 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 120 | type DroiddocProperties struct { |
| 121 | // 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] | 122 | Custom_template *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 123 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 124 | // directories under current module source which contains html/jd files. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 125 | Html_dirs []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 126 | |
| 127 | // set a value in the Clearsilver hdf namespace. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 128 | Hdf []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 129 | |
| 130 | // proofread file contains all of the text content of the javadocs concatenated into one file, |
| 131 | // suitable for spell-checking and other goodness. |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 132 | Proofread_file *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 133 | |
| 134 | // a todo file lists the program elements that are missing documentation. |
| 135 | // At some point, this might be improved to show more warnings. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 136 | Todo_file *string `android:"path"` |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 137 | |
| 138 | // directory under current module source that provide additional resources (images). |
| 139 | Resourcesdir *string |
| 140 | |
| 141 | // resources output directory under out/soong/.intermediates. |
| 142 | Resourcesoutdir *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 143 | |
Nan Zhang | e2ba5d4 | 2018-07-11 15:16:55 -0700 | [diff] [blame] | 144 | // index.html under current module will be copied to docs out dir, if not null. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 145 | Static_doc_index_redirect *string `android:"path"` |
Nan Zhang | e2ba5d4 | 2018-07-11 15:16:55 -0700 | [diff] [blame] | 146 | |
| 147 | // source.properties under current module will be copied to docs out dir, if not null. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 148 | Static_doc_properties *string `android:"path"` |
Nan Zhang | e2ba5d4 | 2018-07-11 15:16:55 -0700 | [diff] [blame] | 149 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 150 | // a list of files under current module source dir which contains known tags in Java sources. |
| 151 | // filegroup or genrule can be included within this property. |
Colin Cross | 27b922f | 2019-03-04 22:35:41 -0800 | [diff] [blame] | 152 | Knowntags []string `android:"path"` |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 153 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 154 | // if set to true, generate docs through Dokka instead of Doclava. |
| 155 | Dokka_enabled *bool |
Mathew Inwood | abd49ab | 2019-12-19 14:27:08 +0000 | [diff] [blame] | 156 | |
| 157 | // Compat config XML. Generates compat change documentation if set. |
| 158 | Compat_config *string `android:"path"` |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 159 | } |
| 160 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 161 | // Common flags passed down to build rule |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 162 | type droiddocBuilderFlags struct { |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 163 | bootClasspathArgs string |
| 164 | classpathArgs string |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 165 | sourcepathArgs string |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 166 | dokkaClasspathArgs string |
| 167 | aidlFlags string |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 168 | aidlDeps android.Paths |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 169 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 170 | doclavaStubsFlags string |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 171 | doclavaDocsFlags string |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 172 | postDoclavaCmds string |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 173 | } |
| 174 | |
| 175 | func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) { |
| 176 | android.InitAndroidArchModule(module, hod, android.MultilibCommon) |
| 177 | android.InitDefaultableModule(module) |
| 178 | } |
| 179 | |
Luca Stefani | d63ea0a | 2019-09-01 21:49:45 +0200 | [diff] [blame] | 180 | func apiCheckEnabled(ctx android.ModuleContext, apiToCheck ApiToCheck, apiVersionTag string) bool { |
| 181 | if ctx.Config().IsEnvTrue("WITHOUT_CHECK_API") { |
| 182 | return false |
| 183 | } else if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" { |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 184 | return true |
| 185 | } else if String(apiToCheck.Api_file) != "" { |
| 186 | panic("for " + apiVersionTag + " removed_api_file has to be non-empty!") |
| 187 | } else if String(apiToCheck.Removed_api_file) != "" { |
| 188 | panic("for " + apiVersionTag + " api_file has to be non-empty!") |
| 189 | } |
| 190 | |
| 191 | return false |
| 192 | } |
| 193 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 194 | // Javadoc |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 195 | type Javadoc struct { |
| 196 | android.ModuleBase |
| 197 | android.DefaultableModuleBase |
| 198 | |
| 199 | properties JavadocProperties |
| 200 | |
| 201 | srcJars android.Paths |
| 202 | srcFiles android.Paths |
| 203 | sourcepaths android.Paths |
Ramy Medhat | c7965cd | 2020-04-30 03:08:37 -0400 | [diff] [blame] | 204 | implicits android.Paths |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 205 | |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 206 | docZip android.WritablePath |
| 207 | stubsSrcJar android.WritablePath |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 208 | } |
| 209 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 210 | func (j *Javadoc) OutputFiles(tag string) (android.Paths, error) { |
| 211 | switch tag { |
| 212 | case "": |
| 213 | return android.Paths{j.stubsSrcJar}, nil |
Colin Cross | e68e554 | 2019-08-12 13:11:40 -0700 | [diff] [blame] | 214 | case ".docs.zip": |
| 215 | return android.Paths{j.docZip}, nil |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 216 | default: |
| 217 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 218 | } |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 219 | } |
| 220 | |
Colin Cross | a3002fc | 2019-07-08 16:48:04 -0700 | [diff] [blame] | 221 | // javadoc converts .java source files to documentation using javadoc. |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 222 | func JavadocFactory() android.Module { |
| 223 | module := &Javadoc{} |
| 224 | |
| 225 | module.AddProperties(&module.properties) |
| 226 | |
| 227 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
| 228 | return module |
| 229 | } |
| 230 | |
Colin Cross | a3002fc | 2019-07-08 16:48:04 -0700 | [diff] [blame] | 231 | // javadoc_host converts .java source files to documentation using javadoc. |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 232 | func JavadocHostFactory() android.Module { |
| 233 | module := &Javadoc{} |
| 234 | |
| 235 | module.AddProperties(&module.properties) |
| 236 | |
| 237 | InitDroiddocModule(module, android.HostSupported) |
| 238 | return module |
| 239 | } |
| 240 | |
Colin Cross | 41955e8 | 2019-05-29 14:40:35 -0700 | [diff] [blame] | 241 | var _ android.OutputFileProducer = (*Javadoc)(nil) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 242 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 243 | func (j *Javadoc) SdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { |
| 244 | return android.SdkSpecFrom(ctx, String(j.properties.Sdk_version)) |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 245 | } |
| 246 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 247 | func (j *Javadoc) SystemModules() string { |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 248 | return proptools.String(j.properties.System_modules) |
| 249 | } |
| 250 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 251 | func (j *Javadoc) MinSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { |
| 252 | return j.SdkVersion(ctx) |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 253 | } |
| 254 | |
William Loh | 5a082f9 | 2022-05-17 20:21:50 +0000 | [diff] [blame] | 255 | func (j *Javadoc) ReplaceMaxSdkVersionPlaceholder(ctx android.EarlyModuleContext) android.SdkSpec { |
| 256 | return j.SdkVersion(ctx) |
| 257 | } |
| 258 | |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 259 | func (j *Javadoc) TargetSdkVersion(ctx android.EarlyModuleContext) android.SdkSpec { |
| 260 | return j.SdkVersion(ctx) |
Dan Willemsen | 419290a | 2018-10-31 15:28:47 -0700 | [diff] [blame] | 261 | } |
| 262 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 263 | func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) { |
| 264 | if ctx.Device() { |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 265 | sdkDep := decodeSdkDep(ctx, android.SdkContext(j)) |
Pete Gillin | e3d44b2 | 2020-06-29 11:28:51 +0100 | [diff] [blame] | 266 | if sdkDep.useModule { |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 267 | ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.bootclasspath...) |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 268 | ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules) |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 269 | ctx.AddVariationDependencies(nil, java9LibTag, sdkDep.java9Classpath...) |
Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame] | 270 | ctx.AddVariationDependencies(nil, sdkLibTag, sdkDep.classpath...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 271 | } |
| 272 | } |
| 273 | |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 274 | ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 275 | } |
| 276 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 277 | func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags { |
| 278 | var flags droiddocBuilderFlags |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 279 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 280 | flags.aidlFlags, flags.aidlDeps = j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs) |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 281 | |
| 282 | return flags |
| 283 | } |
| 284 | |
| 285 | func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath, |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 286 | aidlIncludeDirs android.Paths) (string, android.Paths) { |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 287 | |
| 288 | aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs) |
| 289 | aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...) |
| 290 | |
| 291 | var flags []string |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 292 | var deps android.Paths |
| 293 | |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 294 | if aidlPreprocess.Valid() { |
| 295 | flags = append(flags, "-p"+aidlPreprocess.String()) |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 296 | deps = append(deps, aidlPreprocess.Path()) |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 297 | } else { |
| 298 | flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I")) |
| 299 | } |
| 300 | |
| 301 | flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I")) |
| 302 | flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String()) |
| 303 | if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() { |
| 304 | flags = append(flags, "-I"+src.String()) |
| 305 | } |
| 306 | |
Colin Cross | 3047fa2 | 2019-04-18 10:56:44 -0700 | [diff] [blame] | 307 | return strings.Join(flags, " "), deps |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 308 | } |
| 309 | |
Jiyong Park | d90d741 | 2019-08-20 22:49:19 +0900 | [diff] [blame] | 310 | // TODO: remove the duplication between this and the one in gen.go |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 311 | func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths, |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 312 | flags droiddocBuilderFlags) android.Paths { |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 313 | |
| 314 | outSrcFiles := make(android.Paths, 0, len(srcFiles)) |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 315 | var aidlSrcs android.Paths |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 316 | |
Sam Delmerico | 2351eac | 2022-05-24 17:10:02 +0000 | [diff] [blame] | 317 | aidlIncludeFlags := genAidlIncludeFlags(ctx, srcFiles, android.Paths{}) |
Jiyong Park | 1112c4c | 2019-08-16 21:12:10 +0900 | [diff] [blame] | 318 | |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 319 | for _, srcFile := range srcFiles { |
| 320 | switch srcFile.Ext() { |
| 321 | case ".aidl": |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 322 | aidlSrcs = append(aidlSrcs, srcFile) |
Jiyong Park | d90d741 | 2019-08-20 22:49:19 +0900 | [diff] [blame] | 323 | case ".logtags": |
| 324 | javaFile := genLogtags(ctx, srcFile) |
| 325 | outSrcFiles = append(outSrcFiles, javaFile) |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 326 | default: |
| 327 | outSrcFiles = append(outSrcFiles, srcFile) |
| 328 | } |
| 329 | } |
| 330 | |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 331 | // Process all aidl files together to support sharding them into one or more rules that produce srcjars. |
| 332 | if len(aidlSrcs) > 0 { |
Thiébaud Weksteen | de8417c | 2022-02-10 15:41:46 +1100 | [diff] [blame] | 333 | srcJarFiles := genAidl(ctx, aidlSrcs, flags.aidlFlags+aidlIncludeFlags, nil, flags.aidlDeps) |
Colin Cross | c080617 | 2019-06-14 18:51:47 -0700 | [diff] [blame] | 334 | outSrcFiles = append(outSrcFiles, srcJarFiles...) |
| 335 | } |
| 336 | |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 337 | return outSrcFiles |
| 338 | } |
| 339 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 340 | func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { |
| 341 | var deps deps |
| 342 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 343 | sdkDep := decodeSdkDep(ctx, android.SdkContext(j)) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 344 | if sdkDep.invalidVersion { |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 345 | ctx.AddMissingDependencies(sdkDep.bootclasspath) |
| 346 | ctx.AddMissingDependencies(sdkDep.java9Classpath) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 347 | } else if sdkDep.useFiles { |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 348 | deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...) |
Anton Hansson | 26bf49b | 2020-02-08 20:26:29 +0000 | [diff] [blame] | 349 | deps.aidlPreprocess = sdkDep.aidl |
| 350 | } else { |
| 351 | deps.aidlPreprocess = sdkDep.aidl |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 352 | } |
| 353 | |
| 354 | ctx.VisitDirectDeps(func(module android.Module) { |
| 355 | otherName := ctx.OtherModuleName(module) |
| 356 | tag := ctx.OtherModuleDependencyTag(module) |
| 357 | |
Colin Cross | 2d24c1b | 2018-05-23 10:59:18 -0700 | [diff] [blame] | 358 | switch tag { |
| 359 | case bootClasspathTag: |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 360 | if ctx.OtherModuleHasProvider(module, JavaInfoProvider) { |
| 361 | dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo) |
| 362 | deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars...) |
Paul Duffin | 83a2d96 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 363 | } else if sm, ok := module.(SystemModulesProvider); ok { |
Paul Duffin | e25c644 | 2019-10-11 13:50:28 +0100 | [diff] [blame] | 364 | // A system modules dependency has been added to the bootclasspath |
| 365 | // so add its libs to the bootclasspath. |
Paul Duffin | 83a2d96 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 366 | deps.bootClasspath = append(deps.bootClasspath, sm.HeaderJars()...) |
Colin Cross | 2d24c1b | 2018-05-23 10:59:18 -0700 | [diff] [blame] | 367 | } else { |
| 368 | panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) |
| 369 | } |
Liz Kammer | ef28a4c | 2022-09-23 16:50:56 -0400 | [diff] [blame] | 370 | case libTag, sdkLibTag: |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 371 | if dep, ok := module.(SdkLibraryDependency); ok { |
Jiyong Park | 9231537 | 2021-04-02 08:45:46 +0900 | [diff] [blame] | 372 | deps.classpath = append(deps.classpath, dep.SdkHeaderJars(ctx, j.SdkVersion(ctx))...) |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 373 | } else if ctx.OtherModuleHasProvider(module, JavaInfoProvider) { |
| 374 | dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo) |
| 375 | deps.classpath = append(deps.classpath, dep.HeaderJars...) |
| 376 | deps.aidlIncludeDirs = append(deps.aidlIncludeDirs, dep.AidlIncludeDirs...) |
| 377 | } else if dep, ok := module.(android.SourceFileProducer); ok { |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 378 | checkProducesJars(ctx, dep) |
| 379 | deps.classpath = append(deps.classpath, dep.Srcs()...) |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 380 | } else { |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 381 | ctx.ModuleErrorf("depends on non-java module %q", otherName) |
| 382 | } |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 383 | case java9LibTag: |
Colin Cross | dcf71b2 | 2021-02-01 13:59:03 -0800 | [diff] [blame] | 384 | if ctx.OtherModuleHasProvider(module, JavaInfoProvider) { |
| 385 | dep := ctx.OtherModuleProvider(module, JavaInfoProvider).(JavaInfo) |
| 386 | deps.java9Classpath = append(deps.java9Classpath, dep.HeaderJars...) |
| 387 | } else { |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 388 | ctx.ModuleErrorf("depends on non-java module %q", otherName) |
| 389 | } |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 390 | case systemModulesTag: |
| 391 | if deps.systemModules != nil { |
| 392 | panic("Found two system module dependencies") |
| 393 | } |
Paul Duffin | 83a2d96 | 2019-11-19 19:44:10 +0000 | [diff] [blame] | 394 | sm := module.(SystemModulesProvider) |
| 395 | outputDir, outputDeps := sm.OutputDirAndDeps() |
| 396 | deps.systemModules = &systemModules{outputDir, outputDeps} |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 397 | } |
| 398 | }) |
| 399 | // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs |
| 400 | // may contain filegroup or genrule. |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 401 | srcFiles := android.PathsForModuleSrcExcludes(ctx, j.properties.Srcs, j.properties.Exclude_srcs) |
Ramy Medhat | c7965cd | 2020-04-30 03:08:37 -0400 | [diff] [blame] | 402 | j.implicits = append(j.implicits, srcFiles...) |
Jiyong Park | c6ddccf | 2019-09-13 20:56:14 +0900 | [diff] [blame] | 403 | |
| 404 | filterByPackage := func(srcs []android.Path, filterPackages []string) []android.Path { |
| 405 | if filterPackages == nil { |
| 406 | return srcs |
| 407 | } |
| 408 | filtered := []android.Path{} |
| 409 | for _, src := range srcs { |
| 410 | if src.Ext() != ".java" { |
| 411 | // Don't filter-out non-Java (=generated sources) by package names. This is not ideal, |
| 412 | // but otherwise metalava emits stub sources having references to the generated AIDL classes |
| 413 | // in filtered-out pacages (e.g. com.android.internal.*). |
| 414 | // TODO(b/141149570) We need to fix this by introducing default private constructors or |
| 415 | // fixing metalava to not emit constructors having references to unknown classes. |
| 416 | filtered = append(filtered, src) |
| 417 | continue |
| 418 | } |
| 419 | packageName := strings.ReplaceAll(filepath.Dir(src.Rel()), "/", ".") |
Jaewoong Jung | 3aff578 | 2020-02-11 07:54:35 -0800 | [diff] [blame] | 420 | if android.HasAnyPrefix(packageName, filterPackages) { |
| 421 | filtered = append(filtered, src) |
Jiyong Park | c6ddccf | 2019-09-13 20:56:14 +0900 | [diff] [blame] | 422 | } |
| 423 | } |
| 424 | return filtered |
| 425 | } |
| 426 | srcFiles = filterByPackage(srcFiles, j.properties.Filter_packages) |
| 427 | |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 428 | aidlFlags := j.collectAidlFlags(ctx, deps) |
| 429 | srcFiles = j.genSources(ctx, srcFiles, aidlFlags) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 430 | |
| 431 | // srcs may depend on some genrule output. |
| 432 | j.srcJars = srcFiles.FilterByExt(".srcjar") |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 433 | j.srcJars = append(j.srcJars, deps.srcJars...) |
| 434 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 435 | j.srcFiles = srcFiles.FilterOutByExt(".srcjar") |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 436 | j.srcFiles = append(j.srcFiles, deps.srcs...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 437 | |
Liz Kammer | e1ab250 | 2020-09-10 15:29:25 +0000 | [diff] [blame] | 438 | if len(j.srcFiles) > 0 { |
| 439 | j.sourcepaths = android.PathsForModuleSrc(ctx, []string{"."}) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 440 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 441 | |
Colin Cross | bc13992 | 2021-03-25 18:33:16 -0700 | [diff] [blame] | 442 | return deps |
| 443 | } |
| 444 | |
| 445 | func (j *Javadoc) expandArgs(ctx android.ModuleContext, cmd *android.RuleBuilderCommand) { |
| 446 | var argFiles android.Paths |
Paul Duffin | 99e4a50 | 2019-02-11 15:38:42 +0000 | [diff] [blame] | 447 | argFilesMap := map[string]string{} |
| 448 | argFileLabels := []string{} |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 449 | |
Paul Duffin | 99e4a50 | 2019-02-11 15:38:42 +0000 | [diff] [blame] | 450 | for _, label := range j.properties.Arg_files { |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 451 | var paths = android.PathsForModuleSrc(ctx, []string{label}) |
Paul Duffin | 99e4a50 | 2019-02-11 15:38:42 +0000 | [diff] [blame] | 452 | if _, exists := argFilesMap[label]; !exists { |
Colin Cross | bc13992 | 2021-03-25 18:33:16 -0700 | [diff] [blame] | 453 | argFilesMap[label] = strings.Join(cmd.PathsForInputs(paths), " ") |
Paul Duffin | 99e4a50 | 2019-02-11 15:38:42 +0000 | [diff] [blame] | 454 | argFileLabels = append(argFileLabels, label) |
Colin Cross | bc13992 | 2021-03-25 18:33:16 -0700 | [diff] [blame] | 455 | argFiles = append(argFiles, paths...) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 456 | } else { |
| 457 | ctx.ModuleErrorf("multiple arg_files for %q, %q and %q", |
Paul Duffin | 99e4a50 | 2019-02-11 15:38:42 +0000 | [diff] [blame] | 458 | label, argFilesMap[label], paths) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 459 | } |
| 460 | } |
| 461 | |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 462 | var argsPropertyName string |
| 463 | flags := make([]string, 0) |
| 464 | if j.properties.Args != nil && j.properties.Flags != nil { |
| 465 | ctx.PropertyErrorf("args", "flags is set. Cannot set args") |
| 466 | } else if args := proptools.String(j.properties.Args); args != "" { |
| 467 | flags = append(flags, args) |
| 468 | argsPropertyName = "args" |
| 469 | } else { |
| 470 | flags = append(flags, j.properties.Flags...) |
| 471 | argsPropertyName = "flags" |
| 472 | } |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 473 | |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 474 | for _, flag := range flags { |
Colin Cross | bc13992 | 2021-03-25 18:33:16 -0700 | [diff] [blame] | 475 | expanded, err := android.Expand(flag, func(name string) (string, error) { |
Liz Kammer | 585cac2 | 2020-07-06 09:12:57 -0700 | [diff] [blame] | 476 | if strings.HasPrefix(name, "location ") { |
| 477 | label := strings.TrimSpace(strings.TrimPrefix(name, "location ")) |
| 478 | if paths, ok := argFilesMap[label]; ok { |
| 479 | return paths, nil |
| 480 | } else { |
| 481 | return "", fmt.Errorf("unknown location label %q, expecting one of %q", |
| 482 | label, strings.Join(argFileLabels, ", ")) |
| 483 | } |
| 484 | } else if name == "genDir" { |
| 485 | return android.PathForModuleGen(ctx).String(), nil |
| 486 | } |
| 487 | return "", fmt.Errorf("unknown variable '$(%s)'", name) |
| 488 | }) |
| 489 | |
| 490 | if err != nil { |
| 491 | ctx.PropertyErrorf(argsPropertyName, "%s", err.Error()) |
| 492 | } |
Colin Cross | bc13992 | 2021-03-25 18:33:16 -0700 | [diff] [blame] | 493 | cmd.Flag(expanded) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 494 | } |
| 495 | |
Colin Cross | bc13992 | 2021-03-25 18:33:16 -0700 | [diff] [blame] | 496 | cmd.Implicits(argFiles) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 500 | j.addDeps(ctx) |
| 501 | } |
| 502 | |
| 503 | func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 504 | deps := j.collectDeps(ctx) |
| 505 | |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 506 | j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip") |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 507 | |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 508 | outDir := android.PathForModuleOut(ctx, "out") |
| 509 | srcJarDir := android.PathForModuleOut(ctx, "srcjars") |
| 510 | |
| 511 | j.stubsSrcJar = nil |
| 512 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 513 | rule := android.NewRuleBuilder(pctx, ctx) |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 514 | |
| 515 | rule.Command().Text("rm -rf").Text(outDir.String()) |
| 516 | rule.Command().Text("mkdir -p").Text(outDir.String()) |
| 517 | |
| 518 | srcJarList := zipSyncCmd(ctx, rule, srcJarDir, j.srcJars) |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 519 | |
Jiyong Park | f1691d2 | 2021-03-29 20:11:58 +0900 | [diff] [blame] | 520 | javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), android.SdkContext(j)) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 521 | |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 522 | cmd := javadocSystemModulesCmd(ctx, rule, j.srcFiles, outDir, srcJarDir, srcJarList, |
| 523 | deps.systemModules, deps.classpath, j.sourcepaths) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 524 | |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 525 | cmd.FlagWithArg("-source ", javaVersion.String()). |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 526 | Flag("-J-Xmx1024m"). |
| 527 | Flag("-XDignore.symbol.file"). |
| 528 | Flag("-Xdoclint:none") |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 529 | |
Colin Cross | bc13992 | 2021-03-25 18:33:16 -0700 | [diff] [blame] | 530 | j.expandArgs(ctx, cmd) |
| 531 | |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 532 | rule.Command(). |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 533 | BuiltTool("soong_zip"). |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 534 | Flag("-write_if_changed"). |
| 535 | Flag("-d"). |
| 536 | FlagWithOutput("-o ", j.docZip). |
| 537 | FlagWithArg("-C ", outDir.String()). |
| 538 | FlagWithArg("-D ", outDir.String()) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 539 | |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 540 | rule.Restat() |
| 541 | |
| 542 | zipSyncCleanupCmd(rule, srcJarDir) |
| 543 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 544 | rule.Build("javadoc", "javadoc") |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 545 | } |
| 546 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 547 | // Droiddoc |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 548 | type Droiddoc struct { |
| 549 | Javadoc |
| 550 | |
Liz Kammer | e1ab250 | 2020-09-10 15:29:25 +0000 | [diff] [blame] | 551 | properties DroiddocProperties |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 552 | } |
| 553 | |
Colin Cross | a3002fc | 2019-07-08 16:48:04 -0700 | [diff] [blame] | 554 | // droiddoc converts .java source files to documentation using doclava or dokka. |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 555 | func DroiddocFactory() android.Module { |
| 556 | module := &Droiddoc{} |
| 557 | |
| 558 | module.AddProperties(&module.properties, |
| 559 | &module.Javadoc.properties) |
| 560 | |
| 561 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
| 562 | return module |
| 563 | } |
| 564 | |
Colin Cross | a3002fc | 2019-07-08 16:48:04 -0700 | [diff] [blame] | 565 | // droiddoc_host converts .java source files to documentation using doclava or dokka. |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 566 | func DroiddocHostFactory() android.Module { |
| 567 | module := &Droiddoc{} |
| 568 | |
| 569 | module.AddProperties(&module.properties, |
| 570 | &module.Javadoc.properties) |
| 571 | |
| 572 | InitDroiddocModule(module, android.HostSupported) |
| 573 | return module |
| 574 | } |
| 575 | |
Liz Kammer | e1ab250 | 2020-09-10 15:29:25 +0000 | [diff] [blame] | 576 | func (d *Droiddoc) OutputFiles(tag string) (android.Paths, error) { |
| 577 | switch tag { |
| 578 | case "", ".docs.zip": |
| 579 | return android.Paths{d.Javadoc.docZip}, nil |
| 580 | default: |
| 581 | return nil, fmt.Errorf("unsupported module reference tag %q", tag) |
| 582 | } |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 583 | } |
| 584 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 585 | func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 586 | d.Javadoc.addDeps(ctx) |
| 587 | |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 588 | if String(d.properties.Custom_template) != "" { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 589 | ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template)) |
| 590 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 591 | } |
| 592 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 593 | func (d *Droiddoc) doclavaDocsFlags(ctx android.ModuleContext, cmd *android.RuleBuilderCommand, docletPath classpath) { |
Colin Cross | 2a2e0db | 2020-02-21 16:55:46 -0800 | [diff] [blame] | 594 | buildNumberFile := ctx.Config().BuildNumberFile(ctx) |
Nan Zhang | 443fa52 | 2018-08-20 20:58:28 -0700 | [diff] [blame] | 595 | // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9 |
| 596 | // sources, droiddoc will get sources produced by metalava which will have already stripped out the |
| 597 | // 1.9 language features. |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 598 | cmd.FlagWithArg("-source ", "1.8"). |
| 599 | Flag("-J-Xmx1600m"). |
| 600 | Flag("-J-XX:-OmitStackTraceInFastThrow"). |
| 601 | Flag("-XDignore.symbol.file"). |
| 602 | FlagWithArg("-doclet ", "com.google.doclava.Doclava"). |
| 603 | FlagWithInputList("-docletpath ", docletPath.Paths(), ":"). |
Colin Cross | 2a2e0db | 2020-02-21 16:55:46 -0800 | [diff] [blame] | 604 | FlagWithArg("-hdf page.build ", ctx.Config().BuildId()+"-$(cat "+buildNumberFile.String()+")").OrderOnly(buildNumberFile). |
Elliott Hughes | 26bce34 | 2019-09-12 15:05:13 -0700 | [diff] [blame] | 605 | FlagWithArg("-hdf page.now ", `"$(date -d @$(cat `+ctx.Config().Getenv("BUILD_DATETIME_FILE")+`) "+%d %b %Y %k:%M")" `) |
Nan Zhang | 4613097 | 2018-06-04 11:28:01 -0700 | [diff] [blame] | 606 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 607 | if String(d.properties.Custom_template) == "" { |
| 608 | // TODO: This is almost always droiddoc-templates-sdk |
| 609 | ctx.PropertyErrorf("custom_template", "must specify a template") |
| 610 | } |
| 611 | |
| 612 | ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) { |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 613 | if t, ok := m.(*ExportedDroiddocDir); ok { |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 614 | cmd.FlagWithArg("-templatedir ", t.dir.String()).Implicits(t.deps) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 615 | } else { |
Paul Duffin | 884363e | 2019-12-19 10:21:09 +0000 | [diff] [blame] | 616 | ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_exported_dir", ctx.OtherModuleName(m)) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 617 | } |
| 618 | }) |
| 619 | |
| 620 | if len(d.properties.Html_dirs) > 0 { |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 621 | htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0]) |
| 622 | cmd.FlagWithArg("-htmldir ", htmlDir.String()). |
| 623 | Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[0], "**/*")})) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 624 | } |
| 625 | |
| 626 | if len(d.properties.Html_dirs) > 1 { |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 627 | htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1]) |
| 628 | cmd.FlagWithArg("-htmldir2 ", htmlDir2.String()). |
| 629 | Implicits(android.PathsForModuleSrc(ctx, []string{filepath.Join(d.properties.Html_dirs[1], "**/*")})) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 630 | } |
| 631 | |
| 632 | if len(d.properties.Html_dirs) > 2 { |
| 633 | ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs") |
| 634 | } |
| 635 | |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 636 | knownTags := android.PathsForModuleSrc(ctx, d.properties.Knowntags) |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 637 | cmd.FlagForEachInput("-knowntags ", knownTags) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 638 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 639 | cmd.FlagForEachArg("-hdf ", d.properties.Hdf) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 640 | |
| 641 | if String(d.properties.Proofread_file) != "" { |
| 642 | proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file)) |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 643 | cmd.FlagWithOutput("-proofread ", proofreadFile) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | if String(d.properties.Todo_file) != "" { |
| 647 | // tricky part: |
| 648 | // we should not compute full path for todo_file through PathForModuleOut(). |
| 649 | // the non-standard doclet will get the full path relative to "-o". |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 650 | cmd.FlagWithArg("-todo ", String(d.properties.Todo_file)). |
| 651 | ImplicitOutput(android.PathForModuleOut(ctx, String(d.properties.Todo_file))) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 652 | } |
| 653 | |
| 654 | if String(d.properties.Resourcesdir) != "" { |
| 655 | // TODO: should we add files under resourcesDir to the implicits? It seems that |
| 656 | // resourcesDir is one sub dir of htmlDir |
| 657 | resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir)) |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 658 | cmd.FlagWithArg("-resourcesdir ", resourcesDir.String()) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 659 | } |
| 660 | |
| 661 | if String(d.properties.Resourcesoutdir) != "" { |
| 662 | // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere. |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 663 | cmd.FlagWithArg("-resourcesoutdir ", String(d.properties.Resourcesoutdir)) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 664 | } |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 665 | } |
| 666 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 667 | func (d *Droiddoc) postDoclavaCmds(ctx android.ModuleContext, rule *android.RuleBuilder) { |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 668 | if String(d.properties.Static_doc_index_redirect) != "" { |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 669 | staticDocIndexRedirect := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_index_redirect)) |
| 670 | rule.Command().Text("cp"). |
| 671 | Input(staticDocIndexRedirect). |
| 672 | Output(android.PathForModuleOut(ctx, "out", "index.html")) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 673 | } |
| 674 | |
| 675 | if String(d.properties.Static_doc_properties) != "" { |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 676 | staticDocProperties := android.PathForModuleSrc(ctx, String(d.properties.Static_doc_properties)) |
| 677 | rule.Command().Text("cp"). |
| 678 | Input(staticDocProperties). |
| 679 | Output(android.PathForModuleOut(ctx, "out", "source.properties")) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 680 | } |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 681 | } |
| 682 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 683 | func javadocCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths, |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 684 | outDir, srcJarDir, srcJarList android.Path, sourcepaths android.Paths) *android.RuleBuilderCommand { |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 685 | |
| 686 | cmd := rule.Command(). |
Colin Cross | bc2c8a7 | 2022-09-14 12:45:42 -0700 | [diff] [blame] | 687 | BuiltTool("soong_javac_wrapper").Tool(android.PathForSource(ctx, "prebuilts/jdk/jdk11/linux-x86/bin/javadoc")). |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 688 | Flag(config.JavacVmFlags). |
| 689 | FlagWithArg("-encoding ", "UTF-8"). |
Colin Cross | 70c4741 | 2021-03-12 17:48:14 -0800 | [diff] [blame] | 690 | FlagWithRspFileInputList("@", android.PathForModuleOut(ctx, "javadoc.rsp"), srcs). |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 691 | FlagWithInput("@", srcJarList) |
| 692 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 693 | // TODO(ccross): Remove this if- statement once we finish migration for all Doclava |
| 694 | // based stubs generation. |
| 695 | // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar |
| 696 | // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out |
| 697 | // the correct package name base path. |
| 698 | if len(sourcepaths) > 0 { |
| 699 | cmd.FlagWithList("-sourcepath ", sourcepaths.Strings(), ":") |
| 700 | } else { |
| 701 | cmd.FlagWithArg("-sourcepath ", srcJarDir.String()) |
| 702 | } |
| 703 | |
| 704 | cmd.FlagWithArg("-d ", outDir.String()). |
| 705 | Flag("-quiet") |
| 706 | |
| 707 | return cmd |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 708 | } |
| 709 | |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 710 | func javadocSystemModulesCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths, |
| 711 | outDir, srcJarDir, srcJarList android.Path, systemModules *systemModules, |
| 712 | classpath classpath, sourcepaths android.Paths) *android.RuleBuilderCommand { |
| 713 | |
| 714 | cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths) |
| 715 | |
| 716 | flag, deps := systemModules.FormJavaSystemModulesPath(ctx.Device()) |
| 717 | cmd.Flag(flag).Implicits(deps) |
| 718 | |
| 719 | cmd.FlagWithArg("--patch-module ", "java.base=.") |
| 720 | |
| 721 | if len(classpath) > 0 { |
| 722 | cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":") |
| 723 | } |
| 724 | |
| 725 | return cmd |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 726 | } |
| 727 | |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 728 | func javadocBootclasspathCmd(ctx android.ModuleContext, rule *android.RuleBuilder, srcs android.Paths, |
| 729 | outDir, srcJarDir, srcJarList android.Path, bootclasspath, classpath classpath, |
| 730 | sourcepaths android.Paths) *android.RuleBuilderCommand { |
| 731 | |
| 732 | cmd := javadocCmd(ctx, rule, srcs, outDir, srcJarDir, srcJarList, sourcepaths) |
| 733 | |
| 734 | if len(bootclasspath) == 0 && ctx.Device() { |
| 735 | // explicitly specify -bootclasspath "" if the bootclasspath is empty to |
| 736 | // ensure java does not fall back to the default bootclasspath. |
| 737 | cmd.FlagWithArg("-bootclasspath ", `""`) |
| 738 | } else if len(bootclasspath) > 0 { |
| 739 | cmd.FlagWithInputList("-bootclasspath ", bootclasspath.Paths(), ":") |
| 740 | } |
| 741 | |
| 742 | if len(classpath) > 0 { |
| 743 | cmd.FlagWithInputList("-classpath ", classpath.Paths(), ":") |
| 744 | } |
| 745 | |
| 746 | return cmd |
| 747 | } |
| 748 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 749 | func dokkaCmd(ctx android.ModuleContext, rule *android.RuleBuilder, |
| 750 | outDir, srcJarDir android.Path, bootclasspath, classpath classpath) *android.RuleBuilderCommand { |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 751 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 752 | // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka. |
| 753 | dokkaClasspath := append(bootclasspath.Paths(), classpath.Paths()...) |
| 754 | |
| 755 | return rule.Command(). |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 756 | BuiltTool("dokka"). |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 757 | Flag(config.JavacVmFlags). |
Sorin Basca | 1d68e48 | 2022-09-08 16:48:01 +0100 | [diff] [blame] | 758 | Flag("-J--add-opens=java.base/java.lang=ALL-UNNAMED"). |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 759 | Flag(srcJarDir.String()). |
| 760 | FlagWithInputList("-classpath ", dokkaClasspath, ":"). |
| 761 | FlagWithArg("-format ", "dac"). |
| 762 | FlagWithArg("-dacRoot ", "/reference/kotlin"). |
| 763 | FlagWithArg("-output ", outDir.String()) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 764 | } |
| 765 | |
| 766 | func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 767 | deps := d.Javadoc.collectDeps(ctx) |
| 768 | |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 769 | d.Javadoc.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip") |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 770 | |
Colin Cross | ae5330a | 2021-11-03 13:31:22 -0700 | [diff] [blame] | 771 | jsilver := ctx.Config().HostJavaToolPath(ctx, "jsilver.jar") |
| 772 | doclava := ctx.Config().HostJavaToolPath(ctx, "doclava.jar") |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 773 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 774 | outDir := android.PathForModuleOut(ctx, "out") |
| 775 | srcJarDir := android.PathForModuleOut(ctx, "srcjars") |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 776 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 777 | rule := android.NewRuleBuilder(pctx, ctx) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 778 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 779 | srcJarList := zipSyncCmd(ctx, rule, srcJarDir, d.Javadoc.srcJars) |
| 780 | |
| 781 | var cmd *android.RuleBuilderCommand |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 782 | if Bool(d.properties.Dokka_enabled) { |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 783 | cmd = dokkaCmd(ctx, rule, outDir, srcJarDir, deps.bootClasspath, deps.classpath) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 784 | } else { |
Colin Cross | daa4c67 | 2019-07-15 22:53:46 -0700 | [diff] [blame] | 785 | cmd = javadocBootclasspathCmd(ctx, rule, d.Javadoc.srcFiles, outDir, srcJarDir, srcJarList, |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 786 | deps.bootClasspath, deps.classpath, d.Javadoc.sourcepaths) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 787 | } |
| 788 | |
Colin Cross | bc13992 | 2021-03-25 18:33:16 -0700 | [diff] [blame] | 789 | d.expandArgs(ctx, cmd) |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 790 | |
Mathew Inwood | abd49ab | 2019-12-19 14:27:08 +0000 | [diff] [blame] | 791 | if d.properties.Compat_config != nil { |
| 792 | compatConfig := android.PathForModuleSrc(ctx, String(d.properties.Compat_config)) |
| 793 | cmd.FlagWithInput("-compatconfig ", compatConfig) |
| 794 | } |
| 795 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 796 | var desc string |
| 797 | if Bool(d.properties.Dokka_enabled) { |
| 798 | desc = "dokka" |
| 799 | } else { |
| 800 | d.doclavaDocsFlags(ctx, cmd, classpath{jsilver, doclava}) |
| 801 | |
| 802 | for _, o := range d.Javadoc.properties.Out { |
| 803 | cmd.ImplicitOutput(android.PathForModuleGen(ctx, o)) |
| 804 | } |
| 805 | |
| 806 | d.postDoclavaCmds(ctx, rule) |
| 807 | desc = "doclava" |
| 808 | } |
| 809 | |
| 810 | rule.Command(). |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 811 | BuiltTool("soong_zip"). |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 812 | Flag("-write_if_changed"). |
| 813 | Flag("-d"). |
| 814 | FlagWithOutput("-o ", d.docZip). |
| 815 | FlagWithArg("-C ", outDir.String()). |
| 816 | FlagWithArg("-D ", outDir.String()) |
| 817 | |
Colin Cross | ab05443 | 2019-07-15 16:13:59 -0700 | [diff] [blame] | 818 | rule.Restat() |
| 819 | |
| 820 | zipSyncCleanupCmd(rule, srcJarDir) |
| 821 | |
Colin Cross | f1a035e | 2020-11-16 17:32:30 -0800 | [diff] [blame] | 822 | rule.Build("javadoc", desc) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 823 | } |
| 824 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 825 | // Exported Droiddoc Directory |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 826 | var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"} |
| 827 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 828 | type ExportedDroiddocDirProperties struct { |
| 829 | // path to the directory containing Droiddoc related files. |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 830 | Path *string |
| 831 | } |
| 832 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 833 | type ExportedDroiddocDir struct { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 834 | android.ModuleBase |
| 835 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 836 | properties ExportedDroiddocDirProperties |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 837 | |
| 838 | deps android.Paths |
| 839 | dir android.Path |
| 840 | } |
| 841 | |
Colin Cross | a3002fc | 2019-07-08 16:48:04 -0700 | [diff] [blame] | 842 | // droiddoc_exported_dir exports a directory of html templates or nullability annotations for use by doclava. |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 843 | func ExportedDroiddocDirFactory() android.Module { |
| 844 | module := &ExportedDroiddocDir{} |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 845 | module.AddProperties(&module.properties) |
| 846 | android.InitAndroidModule(module) |
| 847 | return module |
| 848 | } |
| 849 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 850 | func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {} |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 851 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 852 | func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Colin Cross | 07e5161 | 2019-03-05 12:46:40 -0800 | [diff] [blame] | 853 | path := String(d.properties.Path) |
| 854 | d.dir = android.PathForModuleSrc(ctx, path) |
Colin Cross | 8a49795 | 2019-03-05 22:25:09 -0800 | [diff] [blame] | 855 | d.deps = android.PathsForModuleSrc(ctx, []string{filepath.Join(path, "**/*")}) |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 856 | } |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 857 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 858 | // Defaults |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 859 | type DocDefaults struct { |
| 860 | android.ModuleBase |
| 861 | android.DefaultsModuleBase |
| 862 | } |
| 863 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 864 | func DocDefaultsFactory() android.Module { |
| 865 | module := &DocDefaults{} |
| 866 | |
| 867 | module.AddProperties( |
| 868 | &JavadocProperties{}, |
| 869 | &DroiddocProperties{}, |
| 870 | ) |
| 871 | |
| 872 | android.InitDefaultsModule(module) |
| 873 | |
| 874 | return module |
| 875 | } |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 876 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 877 | func zipSyncCmd(ctx android.ModuleContext, rule *android.RuleBuilder, |
| 878 | srcJarDir android.ModuleOutPath, srcJars android.Paths) android.OutputPath { |
| 879 | |
Colin Cross | 1661aff | 2021-03-12 17:56:51 -0800 | [diff] [blame] | 880 | cmd := rule.Command() |
| 881 | cmd.Text("rm -rf").Text(cmd.PathForOutput(srcJarDir)) |
| 882 | cmd = rule.Command() |
| 883 | cmd.Text("mkdir -p").Text(cmd.PathForOutput(srcJarDir)) |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 884 | srcJarList := srcJarDir.Join(ctx, "list") |
| 885 | |
| 886 | rule.Temporary(srcJarList) |
| 887 | |
Colin Cross | 1661aff | 2021-03-12 17:56:51 -0800 | [diff] [blame] | 888 | cmd = rule.Command() |
| 889 | cmd.BuiltTool("zipsync"). |
| 890 | FlagWithArg("-d ", cmd.PathForOutput(srcJarDir)). |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 891 | FlagWithOutput("-l ", srcJarList). |
| 892 | FlagWithArg("-f ", `"*.java"`). |
| 893 | Inputs(srcJars) |
| 894 | |
| 895 | return srcJarList |
| 896 | } |
| 897 | |
| 898 | func zipSyncCleanupCmd(rule *android.RuleBuilder, srcJarDir android.ModuleOutPath) { |
| 899 | rule.Command().Text("rm -rf").Text(srcJarDir.String()) |
| 900 | } |