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