Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1 | // Copyright 2018 Google Inc. All rights reserved. |
| 2 | // |
| 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | // you may not use this file except in compliance with the License. |
| 5 | // You may obtain a copy of the License at |
| 6 | // |
| 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | // |
| 9 | // Unless required by applicable law or agreed to in writing, software |
| 10 | // distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | // See the License for the specific language governing permissions and |
| 13 | // limitations under the License. |
| 14 | |
| 15 | package java |
| 16 | |
| 17 | import ( |
| 18 | "android/soong/android" |
| 19 | "android/soong/java/config" |
| 20 | "fmt" |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 21 | "path/filepath" |
Nan Zhang | 4613097 | 2018-06-04 11:28:01 -0700 | [diff] [blame] | 22 | "runtime" |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 23 | "strings" |
| 24 | |
| 25 | "github.com/google/blueprint" |
| 26 | ) |
| 27 | |
| 28 | var ( |
| 29 | javadoc = pctx.AndroidStaticRule("javadoc", |
| 30 | blueprint.RuleParams{ |
| 31 | Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` + |
Colin Cross | 436b765 | 2018-03-15 16:24:10 -0700 | [diff] [blame] | 32 | `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + |
Nan Zhang | 40b41b4 | 2018-10-02 16:11:17 -0700 | [diff] [blame] | 33 | `${config.SoongJavacWrapper} ${config.JavadocCmd} -encoding UTF-8 @$out.rsp @$srcJarDir/list ` + |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 34 | `$opts $bootclasspathArgs $classpathArgs $sourcepathArgs ` + |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 35 | `-d $outDir -quiet && ` + |
| 36 | `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` + |
Nan Zhang | e2ba5d4 | 2018-07-11 15:16:55 -0700 | [diff] [blame] | 37 | `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir $postDoclavaCmds`, |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 38 | CommandDeps: []string{ |
Colin Cross | 436b765 | 2018-03-15 16:24:10 -0700 | [diff] [blame] | 39 | "${config.ZipSyncCmd}", |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 40 | "${config.JavadocCmd}", |
| 41 | "${config.SoongZipCmd}", |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 42 | }, |
Nan Zhang | 40b41b4 | 2018-10-02 16:11:17 -0700 | [diff] [blame] | 43 | CommandOrderOnly: []string{"${config.SoongJavacWrapper}"}, |
| 44 | Rspfile: "$out.rsp", |
| 45 | RspfileContent: "$in", |
| 46 | Restat: true, |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 47 | }, |
Nan Zhang | af322cc | 2018-06-19 15:15:38 -0700 | [diff] [blame] | 48 | "outDir", "srcJarDir", "stubsDir", "srcJars", "opts", |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 49 | "bootclasspathArgs", "classpathArgs", "sourcepathArgs", "docZip", "postDoclavaCmds") |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 50 | |
| 51 | apiCheck = pctx.AndroidStaticRule("apiCheck", |
| 52 | blueprint.RuleParams{ |
| 53 | Command: `( ${config.ApiCheckCmd} -JXmx1024m -J"classpath $classpath" $opts ` + |
| 54 | `$apiFile $apiFileToCheck $removedApiFile $removedApiFileToCheck ` + |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 55 | `&& touch $out ) || (echo -e "$msg" ; exit 38)`, |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 56 | CommandDeps: []string{ |
| 57 | "${config.ApiCheckCmd}", |
| 58 | }, |
| 59 | }, |
| 60 | "classpath", "opts", "apiFile", "apiFileToCheck", "removedApiFile", "removedApiFileToCheck", "msg") |
| 61 | |
| 62 | updateApi = pctx.AndroidStaticRule("updateApi", |
| 63 | blueprint.RuleParams{ |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 64 | Command: `( ( cp -f $srcApiFile $destApiFile && cp -f $srcRemovedApiFile $destRemovedApiFile ) ` + |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 65 | `&& touch $out ) || (echo failed to update public API ; exit 38)`, |
| 66 | }, |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 67 | "srcApiFile", "destApiFile", "srcRemovedApiFile", "destRemovedApiFile") |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 68 | |
| 69 | metalava = pctx.AndroidStaticRule("metalava", |
| 70 | blueprint.RuleParams{ |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 71 | Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && ` + |
| 72 | `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` + |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 73 | `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 74 | `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` + |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 75 | `$bootclasspathArgs $classpathArgs $sourcepathArgs --no-banner --color --quiet ` + |
| 76 | `$opts && ` + |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 77 | `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`, |
| 78 | CommandDeps: []string{ |
| 79 | "${config.ZipSyncCmd}", |
| 80 | "${config.JavaCmd}", |
| 81 | "${config.MetalavaJar}", |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 82 | "${config.SoongZipCmd}", |
| 83 | }, |
| 84 | Rspfile: "$out.rsp", |
| 85 | RspfileContent: "$in", |
| 86 | Restat: true, |
| 87 | }, |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 88 | "outDir", "srcJarDir", "stubsDir", "srcJars", "javaVersion", "bootclasspathArgs", |
| 89 | "classpathArgs", "sourcepathArgs", "opts") |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 90 | |
| 91 | metalavaApiCheck = pctx.AndroidStaticRule("metalavaApiCheck", |
| 92 | blueprint.RuleParams{ |
| 93 | Command: `( rm -rf "$srcJarDir" && mkdir -p "$srcJarDir" && ` + |
| 94 | `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + |
| 95 | `${config.JavaCmd} -jar ${config.MetalavaJar} -encoding UTF-8 -source $javaVersion @$out.rsp @$srcJarDir/list ` + |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 96 | `$bootclasspathArgs $classpathArgs $sourcepathArgs --no-banner --color --quiet ` + |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 97 | `$opts && touch $out ) || ` + |
| 98 | `( echo -e "$msg" ; exit 38 )`, |
| 99 | CommandDeps: []string{ |
| 100 | "${config.ZipSyncCmd}", |
| 101 | "${config.JavaCmd}", |
| 102 | "${config.MetalavaJar}", |
| 103 | }, |
| 104 | Rspfile: "$out.rsp", |
| 105 | RspfileContent: "$in", |
| 106 | }, |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 107 | "srcJarDir", "srcJars", "javaVersion", "bootclasspathArgs", "classpathArgs", "sourcepathArgs", "opts", "msg") |
| 108 | |
| 109 | dokka = pctx.AndroidStaticRule("dokka", |
| 110 | blueprint.RuleParams{ |
| 111 | Command: `rm -rf "$outDir" "$srcJarDir" "$stubsDir" && ` + |
| 112 | `mkdir -p "$outDir" "$srcJarDir" "$stubsDir" && ` + |
| 113 | `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + |
| 114 | `${config.JavaCmd} -jar ${config.DokkaJar} $srcJarDir ` + |
| 115 | `$classpathArgs -format dac -dacRoot /reference/kotlin -output $outDir $opts && ` + |
| 116 | `${config.SoongZipCmd} -write_if_changed -d -o $docZip -C $outDir -D $outDir && ` + |
| 117 | `${config.SoongZipCmd} -write_if_changed -jar -o $out -C $stubsDir -D $stubsDir`, |
| 118 | CommandDeps: []string{ |
| 119 | "${config.ZipSyncCmd}", |
| 120 | "${config.DokkaJar}", |
| 121 | "${config.MetalavaJar}", |
| 122 | "${config.SoongZipCmd}", |
| 123 | }, |
| 124 | Restat: true, |
| 125 | }, |
| 126 | "outDir", "srcJarDir", "stubsDir", "srcJars", "classpathArgs", "opts", "docZip") |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 127 | ) |
| 128 | |
| 129 | func init() { |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 130 | android.RegisterModuleType("doc_defaults", DocDefaultsFactory) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 131 | android.RegisterModuleType("stubs_defaults", StubsDefaultsFactory) |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 132 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 133 | android.RegisterModuleType("droiddoc", DroiddocFactory) |
| 134 | android.RegisterModuleType("droiddoc_host", DroiddocHostFactory) |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 135 | android.RegisterModuleType("droiddoc_exported_dir", ExportedDroiddocDirFactory) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 136 | android.RegisterModuleType("javadoc", JavadocFactory) |
| 137 | android.RegisterModuleType("javadoc_host", JavadocHostFactory) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 138 | |
| 139 | android.RegisterModuleType("droidstubs", DroidstubsFactory) |
| 140 | android.RegisterModuleType("droidstubs_host", DroidstubsHostFactory) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 141 | } |
| 142 | |
Colin Cross | a1ce2a0 | 2018-06-20 15:19:39 -0700 | [diff] [blame] | 143 | var ( |
| 144 | srcsLibTag = dependencyTag{name: "sources from javalib"} |
| 145 | ) |
| 146 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 147 | type JavadocProperties struct { |
| 148 | // list of source files used to compile the Java module. May be .java, .logtags, .proto, |
| 149 | // or .aidl files. |
| 150 | Srcs []string `android:"arch_variant"` |
| 151 | |
| 152 | // list of directories rooted at the Android.bp file that will |
| 153 | // be added to the search paths for finding source files when passing package names. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 154 | Local_sourcepaths []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 155 | |
| 156 | // list of source files that should not be used to build the Java module. |
| 157 | // This is most useful in the arch/multilib variants to remove non-common files |
| 158 | // filegroup or genrule can be included within this property. |
| 159 | Exclude_srcs []string `android:"arch_variant"` |
| 160 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 161 | // list of java libraries that will be in the classpath. |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 162 | Libs []string `android:"arch_variant"` |
| 163 | |
Nan Zhang | 5994b62 | 2018-09-21 16:39:51 -0700 | [diff] [blame] | 164 | // don't build against the default libraries (bootclasspath, legacy-test, core-junit, |
| 165 | // ext, and framework for device targets) |
| 166 | No_standard_libs *bool |
| 167 | |
Nan Zhang | e66c727 | 2018-03-06 12:59:27 -0800 | [diff] [blame] | 168 | // don't build against the framework libraries (legacy-test, core-junit, |
| 169 | // ext, and framework for device targets) |
| 170 | No_framework_libs *bool |
| 171 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 172 | // the java library (in classpath) for documentation that provides java srcs and srcjars. |
| 173 | Srcs_lib *string |
| 174 | |
| 175 | // the base dirs under srcs_lib will be scanned for java srcs. |
| 176 | Srcs_lib_whitelist_dirs []string |
| 177 | |
| 178 | // the sub dirs under srcs_lib_whitelist_dirs will be scanned for java srcs. |
| 179 | Srcs_lib_whitelist_pkgs []string |
| 180 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 181 | // 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] | 182 | Installable *bool |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 183 | |
| 184 | // if not blank, set to the version of the sdk to compile against |
| 185 | Sdk_version *string `android:"arch_variant"` |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 186 | |
| 187 | Aidl struct { |
| 188 | // Top level directories to pass to aidl tool |
| 189 | Include_dirs []string |
| 190 | |
| 191 | // Directories rooted at the Android.bp file to pass to aidl tool |
| 192 | Local_include_dirs []string |
| 193 | } |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 194 | |
| 195 | // If not blank, set the java version passed to javadoc as -source |
| 196 | Java_version *string |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 197 | |
| 198 | // local files that are used within user customized droiddoc options. |
| 199 | Arg_files []string |
| 200 | |
| 201 | // user customized droiddoc args. |
| 202 | // Available variables for substitution: |
| 203 | // |
| 204 | // $(location <label>): the path to the arg_files with name <label> |
| 205 | Args *string |
| 206 | |
| 207 | // names of the output files used in args that will be generated |
| 208 | Out []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 209 | } |
| 210 | |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 211 | type ApiToCheck struct { |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 212 | // path to the API txt file that the new API extracted from source code is checked |
| 213 | // against. The path can be local to the module or from other module (via :module syntax). |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 214 | Api_file *string |
| 215 | |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 216 | // path to the API txt file that the new @removed API extractd from source code is |
| 217 | // checked against. The path can be local to the module or from other module (via |
| 218 | // :module syntax). |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 219 | Removed_api_file *string |
| 220 | |
Jiyong Park | eeb8a64 | 2018-05-12 22:21:20 +0900 | [diff] [blame] | 221 | // Arguments to the apicheck tool. |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 222 | Args *string |
| 223 | } |
| 224 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 225 | type DroiddocProperties struct { |
| 226 | // 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] | 227 | Custom_template *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 228 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 229 | // directories under current module source which contains html/jd files. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 230 | Html_dirs []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 231 | |
| 232 | // set a value in the Clearsilver hdf namespace. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 233 | Hdf []string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 234 | |
| 235 | // proofread file contains all of the text content of the javadocs concatenated into one file, |
| 236 | // suitable for spell-checking and other goodness. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 237 | Proofread_file *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 238 | |
| 239 | // a todo file lists the program elements that are missing documentation. |
| 240 | // At some point, this might be improved to show more warnings. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 241 | Todo_file *string |
| 242 | |
| 243 | // directory under current module source that provide additional resources (images). |
| 244 | Resourcesdir *string |
| 245 | |
| 246 | // resources output directory under out/soong/.intermediates. |
| 247 | Resourcesoutdir *string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 248 | |
Nan Zhang | e2ba5d4 | 2018-07-11 15:16:55 -0700 | [diff] [blame] | 249 | // if set to true, collect the values used by the Dev tools and |
| 250 | // write them in files packaged with the SDK. Defaults to false. |
| 251 | Write_sdk_values *bool |
| 252 | |
| 253 | // index.html under current module will be copied to docs out dir, if not null. |
| 254 | Static_doc_index_redirect *string |
| 255 | |
| 256 | // source.properties under current module will be copied to docs out dir, if not null. |
| 257 | Static_doc_properties *string |
| 258 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 259 | // a list of files under current module source dir which contains known tags in Java sources. |
| 260 | // filegroup or genrule can be included within this property. |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 261 | Knowntags []string |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 262 | |
| 263 | // the tag name used to distinguish if the API files belong to public/system/test. |
| 264 | Api_tag_name *string |
| 265 | |
| 266 | // the generated public API filename by Doclava. |
| 267 | Api_filename *string |
| 268 | |
David Brazdil | fbe4cc3 | 2018-05-31 13:56:46 +0100 | [diff] [blame] | 269 | // the generated public Dex API filename by Doclava. |
| 270 | Dex_api_filename *string |
| 271 | |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 272 | // the generated private API filename by Doclava. |
| 273 | Private_api_filename *string |
| 274 | |
| 275 | // the generated private Dex API filename by Doclava. |
| 276 | Private_dex_api_filename *string |
| 277 | |
| 278 | // the generated removed API filename by Doclava. |
| 279 | Removed_api_filename *string |
| 280 | |
David Brazdil | aac0c3c | 2018-04-24 16:23:29 +0100 | [diff] [blame] | 281 | // the generated removed Dex API filename by Doclava. |
| 282 | Removed_dex_api_filename *string |
| 283 | |
Mathew Inwood | 76c3de1 | 2018-06-22 15:28:11 +0100 | [diff] [blame] | 284 | // mapping of dex signatures to source file and line number. This is a temporary property and |
| 285 | // will be deleted; you probably shouldn't be using it. |
| 286 | Dex_mapping_filename *string |
| 287 | |
Nan Zhang | 28c68b9 | 2018-03-13 16:17:01 -0700 | [diff] [blame] | 288 | // the generated exact API filename by Doclava. |
| 289 | Exact_api_filename *string |
Nan Zhang | 853f420 | 2018-04-12 16:55:56 -0700 | [diff] [blame] | 290 | |
Nan Zhang | 66dc236 | 2018-08-14 20:41:04 -0700 | [diff] [blame] | 291 | // the generated proguard filename by Doclava. |
| 292 | Proguard_filename *string |
| 293 | |
Nan Zhang | 853f420 | 2018-04-12 16:55:56 -0700 | [diff] [blame] | 294 | // if set to false, don't allow droiddoc to generate stubs source files. Defaults to true. |
| 295 | Create_stubs *bool |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 296 | |
| 297 | Check_api struct { |
| 298 | Last_released ApiToCheck |
| 299 | |
| 300 | Current ApiToCheck |
| 301 | } |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 302 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 303 | // if set to true, generate docs through Dokka instead of Doclava. |
| 304 | Dokka_enabled *bool |
| 305 | } |
| 306 | |
| 307 | type DroidstubsProperties struct { |
| 308 | // the tag name used to distinguish if the API files belong to public/system/test. |
| 309 | Api_tag_name *string |
| 310 | |
Nan Zhang | 199645c | 2018-09-19 12:40:06 -0700 | [diff] [blame] | 311 | // the generated public API filename by Metalava. |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 312 | Api_filename *string |
| 313 | |
Nan Zhang | 199645c | 2018-09-19 12:40:06 -0700 | [diff] [blame] | 314 | // the generated public Dex API filename by Metalava. |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 315 | Dex_api_filename *string |
| 316 | |
Nan Zhang | 199645c | 2018-09-19 12:40:06 -0700 | [diff] [blame] | 317 | // the generated private API filename by Metalava. |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 318 | Private_api_filename *string |
| 319 | |
Nan Zhang | 199645c | 2018-09-19 12:40:06 -0700 | [diff] [blame] | 320 | // the generated private Dex API filename by Metalava. |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 321 | Private_dex_api_filename *string |
| 322 | |
Nan Zhang | 199645c | 2018-09-19 12:40:06 -0700 | [diff] [blame] | 323 | // the generated removed API filename by Metalava. |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 324 | Removed_api_filename *string |
| 325 | |
Nan Zhang | 199645c | 2018-09-19 12:40:06 -0700 | [diff] [blame] | 326 | // the generated removed Dex API filename by Metalava. |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 327 | Removed_dex_api_filename *string |
| 328 | |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 329 | // mapping of dex signatures to source file and line number. This is a temporary property and |
| 330 | // will be deleted; you probably shouldn't be using it. |
| 331 | Dex_mapping_filename *string |
| 332 | |
Nan Zhang | 199645c | 2018-09-19 12:40:06 -0700 | [diff] [blame] | 333 | // the generated exact API filename by Metalava. |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 334 | Exact_api_filename *string |
| 335 | |
Nan Zhang | 199645c | 2018-09-19 12:40:06 -0700 | [diff] [blame] | 336 | // the generated proguard filename by Metalava. |
| 337 | Proguard_filename *string |
| 338 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 339 | Check_api struct { |
| 340 | Last_released ApiToCheck |
| 341 | |
| 342 | Current ApiToCheck |
| 343 | } |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 344 | |
| 345 | // user can specify the version of previous released API file in order to do compatibility check. |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 346 | Previous_api *string |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 347 | |
| 348 | // is set to true, Metalava will allow framework SDK to contain annotations. |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 349 | Annotations_enabled *bool |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 350 | |
Pete Gillin | 7716790 | 2018-09-19 18:16:26 +0100 | [diff] [blame] | 351 | // a list of top-level directories containing files to merge qualifier annotations (i.e. those intended to be included in the stubs written) from. |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 352 | Merge_annotations_dirs []string |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 353 | |
Pete Gillin | 7716790 | 2018-09-19 18:16:26 +0100 | [diff] [blame] | 354 | // a list of top-level directories containing Java stub files to merge show/hide annotations from. |
| 355 | Merge_inclusion_annotations_dirs []string |
| 356 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 357 | // if set to true, allow Metalava to generate doc_stubs source files. Defaults to false. |
| 358 | Create_doc_stubs *bool |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 359 | |
| 360 | // is set to true, Metalava will allow framework SDK to contain API levels annotations. |
| 361 | Api_levels_annotations_enabled *bool |
| 362 | |
| 363 | // the dirs which Metalava extracts API levels annotations from. |
| 364 | Api_levels_annotations_dirs []string |
| 365 | |
| 366 | // if set to true, collect the values used by the Dev tools and |
| 367 | // write them in files packaged with the SDK. Defaults to false. |
| 368 | Write_sdk_values *bool |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 369 | |
| 370 | // If set to true, .xml based public API file will be also generated, and |
| 371 | // JDiff tool will be invoked to genreate javadoc files. Defaults to false. |
| 372 | Jdiff_enabled *bool |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 373 | } |
| 374 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 375 | // |
| 376 | // Common flags passed down to build rule |
| 377 | // |
| 378 | type droiddocBuilderFlags struct { |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 379 | bootClasspathArgs string |
| 380 | classpathArgs string |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 381 | sourcepathArgs string |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 382 | dokkaClasspathArgs string |
| 383 | aidlFlags string |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 384 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 385 | doclavaStubsFlags string |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 386 | doclavaDocsFlags string |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 387 | postDoclavaCmds string |
| 388 | |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 389 | metalavaStubsFlags string |
| 390 | metalavaAnnotationsFlags string |
| 391 | metalavaApiLevelsAnnotationsFlags string |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 392 | |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 393 | metalavaApiToXmlFlags string |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) { |
| 397 | android.InitAndroidArchModule(module, hod, android.MultilibCommon) |
| 398 | android.InitDefaultableModule(module) |
| 399 | } |
| 400 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 401 | func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool { |
| 402 | if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" { |
| 403 | return true |
| 404 | } else if String(apiToCheck.Api_file) != "" { |
| 405 | panic("for " + apiVersionTag + " removed_api_file has to be non-empty!") |
| 406 | } else if String(apiToCheck.Removed_api_file) != "" { |
| 407 | panic("for " + apiVersionTag + " api_file has to be non-empty!") |
| 408 | } |
| 409 | |
| 410 | return false |
| 411 | } |
| 412 | |
| 413 | type ApiFilePath interface { |
| 414 | ApiFilePath() android.Path |
| 415 | } |
| 416 | |
| 417 | func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile, |
| 418 | srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) { |
| 419 | ctx.Build(pctx, android.BuildParams{ |
| 420 | Rule: updateApi, |
| 421 | Description: "Update API", |
| 422 | Output: output, |
| 423 | Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile, |
| 424 | destApiFile, destRemovedApiFile), |
| 425 | Args: map[string]string{ |
| 426 | "destApiFile": destApiFile.String(), |
| 427 | "srcApiFile": srcApiFile.String(), |
| 428 | "destRemovedApiFile": destRemovedApiFile.String(), |
| 429 | "srcRemovedApiFile": srcRemovedApiFile.String(), |
| 430 | }, |
| 431 | }) |
| 432 | } |
| 433 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 434 | // |
| 435 | // Javadoc |
| 436 | // |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 437 | type Javadoc struct { |
| 438 | android.ModuleBase |
| 439 | android.DefaultableModuleBase |
| 440 | |
| 441 | properties JavadocProperties |
| 442 | |
| 443 | srcJars android.Paths |
| 444 | srcFiles android.Paths |
| 445 | sourcepaths android.Paths |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 446 | argFiles android.Paths |
| 447 | |
| 448 | args string |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 449 | |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 450 | docZip android.WritablePath |
| 451 | stubsSrcJar android.WritablePath |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 452 | } |
| 453 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 454 | func (j *Javadoc) Srcs() android.Paths { |
| 455 | return android.Paths{j.stubsSrcJar} |
| 456 | } |
| 457 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 458 | func JavadocFactory() android.Module { |
| 459 | module := &Javadoc{} |
| 460 | |
| 461 | module.AddProperties(&module.properties) |
| 462 | |
| 463 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
| 464 | return module |
| 465 | } |
| 466 | |
| 467 | func JavadocHostFactory() android.Module { |
| 468 | module := &Javadoc{} |
| 469 | |
| 470 | module.AddProperties(&module.properties) |
| 471 | |
| 472 | InitDroiddocModule(module, android.HostSupported) |
| 473 | return module |
| 474 | } |
| 475 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 476 | var _ android.SourceFileProducer = (*Javadoc)(nil) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 477 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 478 | func (j *Javadoc) sdkVersion() string { |
| 479 | return String(j.properties.Sdk_version) |
| 480 | } |
| 481 | |
| 482 | func (j *Javadoc) minSdkVersion() string { |
| 483 | return j.sdkVersion() |
| 484 | } |
| 485 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 486 | func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) { |
| 487 | if ctx.Device() { |
Nan Zhang | 5994b62 | 2018-09-21 16:39:51 -0700 | [diff] [blame] | 488 | if !Bool(j.properties.No_standard_libs) { |
| 489 | sdkDep := decodeSdkDep(ctx, sdkContext(j)) |
| 490 | if sdkDep.useDefaultLibs { |
| 491 | ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...) |
| 492 | if ctx.Config().TargetOpenJDK9() { |
| 493 | ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules) |
| 494 | } |
| 495 | if !Bool(j.properties.No_framework_libs) { |
| 496 | ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...) |
| 497 | } |
| 498 | } else if sdkDep.useModule { |
| 499 | if ctx.Config().TargetOpenJDK9() { |
| 500 | ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules) |
| 501 | } |
| 502 | ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...) |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 503 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 504 | } |
| 505 | } |
| 506 | |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 507 | ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) |
Colin Cross | a1ce2a0 | 2018-06-20 15:19:39 -0700 | [diff] [blame] | 508 | if j.properties.Srcs_lib != nil { |
Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 509 | ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib) |
Colin Cross | a1ce2a0 | 2018-06-20 15:19:39 -0700 | [diff] [blame] | 510 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 511 | |
| 512 | android.ExtractSourcesDeps(ctx, j.properties.Srcs) |
| 513 | |
| 514 | // exclude_srcs may contain filegroup or genrule. |
| 515 | android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 516 | |
| 517 | // arg_files may contains filegroup or genrule. |
| 518 | android.ExtractSourcesDeps(ctx, j.properties.Arg_files) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 519 | } |
| 520 | |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 521 | func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) { |
| 522 | for _, dir := range j.properties.Srcs_lib_whitelist_dirs { |
| 523 | for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs { |
Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 524 | // convert foo.bar.baz to foo/bar/baz |
| 525 | pkgAsPath := filepath.Join(strings.Split(pkg, ".")...) |
| 526 | prefix := filepath.Join(dir, pkgAsPath) |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 527 | if _, found := whitelistPathPrefixes[prefix]; !found { |
| 528 | whitelistPathPrefixes[prefix] = true |
| 529 | } |
| 530 | } |
| 531 | } |
| 532 | } |
| 533 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 534 | func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags { |
| 535 | var flags droiddocBuilderFlags |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 536 | |
| 537 | // aidl flags. |
| 538 | aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs) |
| 539 | if len(aidlFlags) > 0 { |
| 540 | // optimization. |
| 541 | ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " ")) |
| 542 | flags.aidlFlags = "$aidlFlags" |
| 543 | } |
| 544 | |
| 545 | return flags |
| 546 | } |
| 547 | |
| 548 | func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath, |
| 549 | aidlIncludeDirs android.Paths) []string { |
| 550 | |
| 551 | aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs) |
| 552 | aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...) |
| 553 | |
| 554 | var flags []string |
| 555 | if aidlPreprocess.Valid() { |
| 556 | flags = append(flags, "-p"+aidlPreprocess.String()) |
| 557 | } else { |
| 558 | flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I")) |
| 559 | } |
| 560 | |
| 561 | flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I")) |
| 562 | flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String()) |
| 563 | if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() { |
| 564 | flags = append(flags, "-I"+src.String()) |
| 565 | } |
| 566 | |
| 567 | return flags |
| 568 | } |
| 569 | |
| 570 | func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths, |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 571 | flags droiddocBuilderFlags) android.Paths { |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 572 | |
| 573 | outSrcFiles := make(android.Paths, 0, len(srcFiles)) |
| 574 | |
| 575 | for _, srcFile := range srcFiles { |
| 576 | switch srcFile.Ext() { |
| 577 | case ".aidl": |
| 578 | javaFile := genAidl(ctx, srcFile, flags.aidlFlags) |
| 579 | outSrcFiles = append(outSrcFiles, javaFile) |
| 580 | default: |
| 581 | outSrcFiles = append(outSrcFiles, srcFile) |
| 582 | } |
| 583 | } |
| 584 | |
| 585 | return outSrcFiles |
| 586 | } |
| 587 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 588 | func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { |
| 589 | var deps deps |
| 590 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 591 | sdkDep := decodeSdkDep(ctx, sdkContext(j)) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 592 | if sdkDep.invalidVersion { |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 593 | ctx.AddMissingDependencies(sdkDep.modules) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 594 | } else if sdkDep.useFiles { |
Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 595 | deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 596 | } |
| 597 | |
| 598 | ctx.VisitDirectDeps(func(module android.Module) { |
| 599 | otherName := ctx.OtherModuleName(module) |
| 600 | tag := ctx.OtherModuleDependencyTag(module) |
| 601 | |
Colin Cross | 2d24c1b | 2018-05-23 10:59:18 -0700 | [diff] [blame] | 602 | switch tag { |
| 603 | case bootClasspathTag: |
| 604 | if dep, ok := module.(Dependency); ok { |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 605 | deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...) |
Colin Cross | 2d24c1b | 2018-05-23 10:59:18 -0700 | [diff] [blame] | 606 | } else { |
| 607 | panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) |
| 608 | } |
| 609 | case libTag: |
| 610 | switch dep := module.(type) { |
| 611 | case Dependency: |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 612 | deps.classpath = append(deps.classpath, dep.ImplementationJars()...) |
Colin Cross | 2d24c1b | 2018-05-23 10:59:18 -0700 | [diff] [blame] | 613 | case SdkLibraryDependency: |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 614 | sdkVersion := j.sdkVersion() |
Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 615 | linkType := javaSdk |
| 616 | if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") { |
| 617 | linkType = javaSystem |
| 618 | } else if sdkVersion == "" { |
| 619 | linkType = javaPlatform |
| 620 | } |
Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 621 | deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...) |
Colin Cross | 2d24c1b | 2018-05-23 10:59:18 -0700 | [diff] [blame] | 622 | case android.SourceFileProducer: |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 623 | checkProducesJars(ctx, dep) |
| 624 | deps.classpath = append(deps.classpath, dep.Srcs()...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 625 | default: |
| 626 | ctx.ModuleErrorf("depends on non-java module %q", otherName) |
| 627 | } |
Colin Cross | a1ce2a0 | 2018-06-20 15:19:39 -0700 | [diff] [blame] | 628 | case srcsLibTag: |
| 629 | switch dep := module.(type) { |
| 630 | case Dependency: |
| 631 | srcs := dep.(SrcDependency).CompiledSrcs() |
| 632 | whitelistPathPrefixes := make(map[string]bool) |
| 633 | j.genWhitelistPathPrefixes(whitelistPathPrefixes) |
| 634 | for _, src := range srcs { |
| 635 | if _, ok := src.(android.WritablePath); ok { // generated sources |
| 636 | deps.srcs = append(deps.srcs, src) |
| 637 | } else { // select source path for documentation based on whitelist path prefixs. |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 638 | for k := range whitelistPathPrefixes { |
Colin Cross | a1ce2a0 | 2018-06-20 15:19:39 -0700 | [diff] [blame] | 639 | if strings.HasPrefix(src.Rel(), k) { |
| 640 | deps.srcs = append(deps.srcs, src) |
| 641 | break |
| 642 | } |
| 643 | } |
| 644 | } |
| 645 | } |
| 646 | deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...) |
| 647 | default: |
| 648 | ctx.ModuleErrorf("depends on non-java module %q", otherName) |
| 649 | } |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 650 | case systemModulesTag: |
| 651 | if deps.systemModules != nil { |
| 652 | panic("Found two system module dependencies") |
| 653 | } |
| 654 | sm := module.(*SystemModules) |
| 655 | if sm.outputFile == nil { |
| 656 | panic("Missing directory for system module dependency") |
| 657 | } |
| 658 | deps.systemModules = sm.outputFile |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 659 | } |
| 660 | }) |
| 661 | // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs |
| 662 | // may contain filegroup or genrule. |
| 663 | srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 664 | flags := j.collectAidlFlags(ctx, deps) |
Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 665 | srcFiles = j.genSources(ctx, srcFiles, flags) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 666 | |
| 667 | // srcs may depend on some genrule output. |
| 668 | j.srcJars = srcFiles.FilterByExt(".srcjar") |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 669 | j.srcJars = append(j.srcJars, deps.srcJars...) |
| 670 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 671 | j.srcFiles = srcFiles.FilterOutByExt(".srcjar") |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 672 | j.srcFiles = append(j.srcFiles, deps.srcs...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 673 | |
| 674 | j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip") |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 675 | j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar") |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 676 | |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 677 | if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 { |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 678 | j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".") |
| 679 | } |
| 680 | j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 681 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 682 | j.argFiles = ctx.ExpandSources(j.properties.Arg_files, nil) |
| 683 | argFilesMap := map[string]android.Path{} |
| 684 | |
| 685 | for _, f := range j.argFiles { |
| 686 | if _, exists := argFilesMap[f.Rel()]; !exists { |
| 687 | argFilesMap[f.Rel()] = f |
| 688 | } else { |
| 689 | ctx.ModuleErrorf("multiple arg_files for %q, %q and %q", |
| 690 | f, argFilesMap[f.Rel()], f.Rel()) |
| 691 | } |
| 692 | } |
| 693 | |
| 694 | var err error |
| 695 | j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) { |
| 696 | if strings.HasPrefix(name, "location ") { |
| 697 | label := strings.TrimSpace(strings.TrimPrefix(name, "location ")) |
| 698 | if f, ok := argFilesMap[label]; ok { |
| 699 | return f.String(), nil |
| 700 | } else { |
| 701 | return "", fmt.Errorf("unknown location label %q", label) |
| 702 | } |
| 703 | } else if name == "genDir" { |
| 704 | return android.PathForModuleGen(ctx).String(), nil |
| 705 | } |
| 706 | return "", fmt.Errorf("unknown variable '$(%s)'", name) |
| 707 | }) |
| 708 | |
| 709 | if err != nil { |
| 710 | ctx.PropertyErrorf("args", "%s", err.Error()) |
| 711 | } |
| 712 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 713 | return deps |
| 714 | } |
| 715 | |
| 716 | func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 717 | j.addDeps(ctx) |
| 718 | } |
| 719 | |
| 720 | func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 721 | deps := j.collectDeps(ctx) |
| 722 | |
| 723 | var implicits android.Paths |
| 724 | implicits = append(implicits, deps.bootClasspath...) |
| 725 | implicits = append(implicits, deps.classpath...) |
| 726 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 727 | var bootClasspathArgs, classpathArgs, sourcepathArgs string |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 728 | |
Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 729 | javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j)) |
Colin Cross | 997262f | 2018-06-19 22:49:39 -0700 | [diff] [blame] | 730 | if len(deps.bootClasspath) > 0 { |
| 731 | var systemModules classpath |
| 732 | if deps.systemModules != nil { |
| 733 | systemModules = append(systemModules, deps.systemModules) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 734 | } |
Colin Cross | 997262f | 2018-06-19 22:49:39 -0700 | [diff] [blame] | 735 | bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device()) |
| 736 | bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=." |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 737 | } |
| 738 | if len(deps.classpath.Strings()) > 0 { |
| 739 | classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":") |
| 740 | } |
| 741 | |
| 742 | implicits = append(implicits, j.srcJars...) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 743 | implicits = append(implicits, j.argFiles...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 744 | |
Nan Zhang | af322cc | 2018-06-19 15:15:38 -0700 | [diff] [blame] | 745 | opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none" |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 746 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 747 | sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":") |
| 748 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 749 | ctx.Build(pctx, android.BuildParams{ |
| 750 | Rule: javadoc, |
| 751 | Description: "Javadoc", |
Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 752 | Output: j.stubsSrcJar, |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 753 | ImplicitOutput: j.docZip, |
| 754 | Inputs: j.srcFiles, |
| 755 | Implicits: implicits, |
| 756 | Args: map[string]string{ |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 757 | "outDir": android.PathForModuleOut(ctx, "out").String(), |
| 758 | "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(), |
| 759 | "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(), |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 760 | "srcJars": strings.Join(j.srcJars.Strings(), " "), |
| 761 | "opts": opts, |
Nan Zhang | 853f420 | 2018-04-12 16:55:56 -0700 | [diff] [blame] | 762 | "bootclasspathArgs": bootClasspathArgs, |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 763 | "classpathArgs": classpathArgs, |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 764 | "sourcepathArgs": sourcepathArgs, |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 765 | "docZip": j.docZip.String(), |
| 766 | }, |
| 767 | }) |
| 768 | } |
| 769 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 770 | // |
| 771 | // Droiddoc |
| 772 | // |
| 773 | type Droiddoc struct { |
| 774 | Javadoc |
| 775 | |
| 776 | properties DroiddocProperties |
| 777 | apiFile android.WritablePath |
| 778 | dexApiFile android.WritablePath |
| 779 | privateApiFile android.WritablePath |
| 780 | privateDexApiFile android.WritablePath |
| 781 | removedApiFile android.WritablePath |
| 782 | removedDexApiFile android.WritablePath |
| 783 | exactApiFile android.WritablePath |
| 784 | apiMappingFile android.WritablePath |
Nan Zhang | 66dc236 | 2018-08-14 20:41:04 -0700 | [diff] [blame] | 785 | proguardFile android.WritablePath |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 786 | |
| 787 | checkCurrentApiTimestamp android.WritablePath |
| 788 | updateCurrentApiTimestamp android.WritablePath |
| 789 | checkLastReleasedApiTimestamp android.WritablePath |
| 790 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 791 | apiFilePath android.Path |
| 792 | } |
| 793 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 794 | func DroiddocFactory() android.Module { |
| 795 | module := &Droiddoc{} |
| 796 | |
| 797 | module.AddProperties(&module.properties, |
| 798 | &module.Javadoc.properties) |
| 799 | |
| 800 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
| 801 | return module |
| 802 | } |
| 803 | |
| 804 | func DroiddocHostFactory() android.Module { |
| 805 | module := &Droiddoc{} |
| 806 | |
| 807 | module.AddProperties(&module.properties, |
| 808 | &module.Javadoc.properties) |
| 809 | |
| 810 | InitDroiddocModule(module, android.HostSupported) |
| 811 | return module |
| 812 | } |
| 813 | |
| 814 | func (d *Droiddoc) ApiFilePath() android.Path { |
| 815 | return d.apiFilePath |
| 816 | } |
| 817 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 818 | func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 819 | d.Javadoc.addDeps(ctx) |
| 820 | |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 821 | if String(d.properties.Custom_template) != "" { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 822 | ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template)) |
| 823 | } |
| 824 | |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 825 | // knowntags may contain filegroup or genrule. |
| 826 | android.ExtractSourcesDeps(ctx, d.properties.Knowntags) |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 827 | |
Nan Zhang | e2ba5d4 | 2018-07-11 15:16:55 -0700 | [diff] [blame] | 828 | if String(d.properties.Static_doc_index_redirect) != "" { |
| 829 | android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect) |
| 830 | } |
| 831 | |
| 832 | if String(d.properties.Static_doc_properties) != "" { |
| 833 | android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties) |
| 834 | } |
| 835 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 836 | if apiCheckEnabled(d.properties.Check_api.Current, "current") { |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 837 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file) |
| 838 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file) |
| 839 | } |
| 840 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 841 | if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") { |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 842 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file) |
| 843 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file) |
| 844 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 845 | } |
| 846 | |
Nan Zhang | 66dc236 | 2018-08-14 20:41:04 -0700 | [diff] [blame] | 847 | func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths, |
| 848 | deps deps) (droiddocBuilderFlags, error) { |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 849 | var flags droiddocBuilderFlags |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 850 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 851 | *implicits = append(*implicits, deps.bootClasspath...) |
| 852 | *implicits = append(*implicits, deps.classpath...) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 853 | |
Nan Zhang | c94f9d8 | 2018-06-26 10:02:26 -0700 | [diff] [blame] | 854 | if len(deps.bootClasspath.Strings()) > 0 { |
| 855 | // For OpenJDK 8 we can use -bootclasspath to define the core libraries code. |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 856 | flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath") |
Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 857 | } |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 858 | flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath") |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 859 | // Dokka doesn't support bootClasspath, so combine these two classpath vars for Dokka. |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 860 | dokkaClasspath := classpath{} |
| 861 | dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...) |
| 862 | dokkaClasspath = append(dokkaClasspath, deps.classpath...) |
| 863 | flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath") |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 864 | |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 865 | // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava |
| 866 | // based stubs generation. |
| 867 | // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar |
| 868 | // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out |
| 869 | // the correct package name base path. |
| 870 | if len(d.Javadoc.properties.Local_sourcepaths) > 0 { |
| 871 | flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") |
| 872 | } else { |
| 873 | flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String() |
| 874 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 875 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 876 | return flags, nil |
| 877 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 878 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 879 | func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths, |
Nan Zhang | 443fa52 | 2018-08-20 20:58:28 -0700 | [diff] [blame] | 880 | jsilver, doclava android.Path) string { |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 881 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 882 | *implicits = append(*implicits, jsilver) |
| 883 | *implicits = append(*implicits, doclava) |
Nan Zhang | 3096374 | 2018-04-23 09:59:14 -0700 | [diff] [blame] | 884 | |
Nan Zhang | 4613097 | 2018-06-04 11:28:01 -0700 | [diff] [blame] | 885 | var date string |
| 886 | if runtime.GOOS == "darwin" { |
| 887 | date = `date -r` |
| 888 | } else { |
| 889 | date = `date -d` |
| 890 | } |
| 891 | |
Nan Zhang | 443fa52 | 2018-08-20 20:58:28 -0700 | [diff] [blame] | 892 | // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources. For modules with 1.9 |
| 893 | // sources, droiddoc will get sources produced by metalava which will have already stripped out the |
| 894 | // 1.9 language features. |
| 895 | args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " + |
Nan Zhang | 3096374 | 2018-04-23 09:59:14 -0700 | [diff] [blame] | 896 | "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " + |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 897 | "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " + |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 898 | `-hdf page.now "$$(` + date + ` @$$(cat ` + ctx.Config().Getenv("BUILD_DATETIME_FILE") + `) "+%d %b %Y %k:%M")" ` |
Nan Zhang | 4613097 | 2018-06-04 11:28:01 -0700 | [diff] [blame] | 899 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 900 | if String(d.properties.Custom_template) == "" { |
| 901 | // TODO: This is almost always droiddoc-templates-sdk |
| 902 | ctx.PropertyErrorf("custom_template", "must specify a template") |
| 903 | } |
| 904 | |
| 905 | ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) { |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 906 | if t, ok := m.(*ExportedDroiddocDir); ok { |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 907 | *implicits = append(*implicits, t.deps...) |
| 908 | args = args + " -templatedir " + t.dir.String() |
| 909 | } else { |
| 910 | ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m)) |
| 911 | } |
| 912 | }) |
| 913 | |
| 914 | if len(d.properties.Html_dirs) > 0 { |
| 915 | htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0]) |
| 916 | *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...) |
| 917 | args = args + " -htmldir " + htmlDir.String() |
| 918 | } |
| 919 | |
| 920 | if len(d.properties.Html_dirs) > 1 { |
| 921 | htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1]) |
| 922 | *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...) |
| 923 | args = args + " -htmldir2 " + htmlDir2.String() |
| 924 | } |
| 925 | |
| 926 | if len(d.properties.Html_dirs) > 2 { |
| 927 | ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs") |
| 928 | } |
| 929 | |
| 930 | knownTags := ctx.ExpandSources(d.properties.Knowntags, nil) |
| 931 | *implicits = append(*implicits, knownTags...) |
| 932 | |
| 933 | for _, kt := range knownTags { |
| 934 | args = args + " -knowntags " + kt.String() |
| 935 | } |
| 936 | |
| 937 | for _, hdf := range d.properties.Hdf { |
| 938 | args = args + " -hdf " + hdf |
| 939 | } |
| 940 | |
| 941 | if String(d.properties.Proofread_file) != "" { |
| 942 | proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file)) |
| 943 | args = args + " -proofread " + proofreadFile.String() |
| 944 | } |
| 945 | |
| 946 | if String(d.properties.Todo_file) != "" { |
| 947 | // tricky part: |
| 948 | // we should not compute full path for todo_file through PathForModuleOut(). |
| 949 | // the non-standard doclet will get the full path relative to "-o". |
| 950 | args = args + " -todo " + String(d.properties.Todo_file) |
| 951 | } |
| 952 | |
| 953 | if String(d.properties.Resourcesdir) != "" { |
| 954 | // TODO: should we add files under resourcesDir to the implicits? It seems that |
| 955 | // resourcesDir is one sub dir of htmlDir |
| 956 | resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir)) |
| 957 | args = args + " -resourcesdir " + resourcesDir.String() |
| 958 | } |
| 959 | |
| 960 | if String(d.properties.Resourcesoutdir) != "" { |
| 961 | // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere. |
| 962 | args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir) |
| 963 | } |
| 964 | return args |
| 965 | } |
| 966 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 967 | func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext, |
| 968 | implicitOutputs *android.WritablePaths) string { |
| 969 | var doclavaFlags string |
| 970 | if apiCheckEnabled(d.properties.Check_api.Current, "current") || |
| 971 | apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") || |
| 972 | String(d.properties.Api_filename) != "" { |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 973 | d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt") |
| 974 | doclavaFlags += " -api " + d.apiFile.String() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 975 | *implicitOutputs = append(*implicitOutputs, d.apiFile) |
| 976 | d.apiFilePath = d.apiFile |
| 977 | } |
| 978 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 979 | if apiCheckEnabled(d.properties.Check_api.Current, "current") || |
| 980 | apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") || |
| 981 | String(d.properties.Removed_api_filename) != "" { |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 982 | d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt") |
| 983 | doclavaFlags += " -removedApi " + d.removedApiFile.String() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 984 | *implicitOutputs = append(*implicitOutputs, d.removedApiFile) |
| 985 | } |
| 986 | |
| 987 | if String(d.properties.Private_api_filename) != "" { |
| 988 | d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename)) |
| 989 | doclavaFlags += " -privateApi " + d.privateApiFile.String() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 990 | *implicitOutputs = append(*implicitOutputs, d.privateApiFile) |
| 991 | } |
| 992 | |
| 993 | if String(d.properties.Dex_api_filename) != "" { |
| 994 | d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename)) |
| 995 | doclavaFlags += " -dexApi " + d.dexApiFile.String() |
| 996 | *implicitOutputs = append(*implicitOutputs, d.dexApiFile) |
| 997 | } |
| 998 | |
| 999 | if String(d.properties.Private_dex_api_filename) != "" { |
| 1000 | d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename)) |
| 1001 | doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1002 | *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile) |
| 1003 | } |
| 1004 | |
| 1005 | if String(d.properties.Removed_dex_api_filename) != "" { |
| 1006 | d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename)) |
| 1007 | doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1008 | *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile) |
| 1009 | } |
| 1010 | |
| 1011 | if String(d.properties.Exact_api_filename) != "" { |
| 1012 | d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename)) |
| 1013 | doclavaFlags += " -exactApi " + d.exactApiFile.String() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1014 | *implicitOutputs = append(*implicitOutputs, d.exactApiFile) |
| 1015 | } |
| 1016 | |
| 1017 | if String(d.properties.Dex_mapping_filename) != "" { |
| 1018 | d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename)) |
| 1019 | doclavaFlags += " -apiMapping " + d.apiMappingFile.String() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1020 | *implicitOutputs = append(*implicitOutputs, d.apiMappingFile) |
| 1021 | } |
| 1022 | |
Nan Zhang | 66dc236 | 2018-08-14 20:41:04 -0700 | [diff] [blame] | 1023 | if String(d.properties.Proguard_filename) != "" { |
| 1024 | d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename)) |
| 1025 | doclavaFlags += " -proguard " + d.proguardFile.String() |
Nan Zhang | 66dc236 | 2018-08-14 20:41:04 -0700 | [diff] [blame] | 1026 | *implicitOutputs = append(*implicitOutputs, d.proguardFile) |
| 1027 | } |
| 1028 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1029 | if BoolDefault(d.properties.Create_stubs, true) { |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 1030 | doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1031 | } |
| 1032 | |
| 1033 | if Bool(d.properties.Write_sdk_values) { |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 1034 | doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1035 | } |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1036 | |
| 1037 | return doclavaFlags |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1038 | } |
| 1039 | |
| 1040 | func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string { |
| 1041 | var cmds string |
| 1042 | if String(d.properties.Static_doc_index_redirect) != "" { |
| 1043 | static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect), |
| 1044 | "static_doc_index_redirect") |
| 1045 | *implicits = append(*implicits, static_doc_index_redirect) |
| 1046 | cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " + |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 1047 | android.PathForModuleOut(ctx, "out", "index.html").String() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1048 | } |
| 1049 | |
| 1050 | if String(d.properties.Static_doc_properties) != "" { |
| 1051 | static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties), |
| 1052 | "static_doc_properties") |
| 1053 | *implicits = append(*implicits, static_doc_properties) |
| 1054 | cmds = cmds + " && cp " + static_doc_properties.String() + " " + |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 1055 | android.PathForModuleOut(ctx, "out", "source.properties").String() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1056 | } |
| 1057 | return cmds |
| 1058 | } |
| 1059 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1060 | func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths, |
| 1061 | implicitOutputs android.WritablePaths, |
| 1062 | bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) { |
| 1063 | ctx.Build(pctx, android.BuildParams{ |
| 1064 | Rule: javadoc, |
| 1065 | Description: "Doclava", |
| 1066 | Output: d.Javadoc.stubsSrcJar, |
| 1067 | Inputs: d.Javadoc.srcFiles, |
| 1068 | Implicits: implicits, |
| 1069 | ImplicitOutputs: implicitOutputs, |
| 1070 | Args: map[string]string{ |
| 1071 | "outDir": android.PathForModuleOut(ctx, "out").String(), |
| 1072 | "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(), |
| 1073 | "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(), |
| 1074 | "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "), |
| 1075 | "opts": opts, |
| 1076 | "bootclasspathArgs": bootclasspathArgs, |
| 1077 | "classpathArgs": classpathArgs, |
| 1078 | "sourcepathArgs": sourcepathArgs, |
| 1079 | "docZip": d.Javadoc.docZip.String(), |
| 1080 | "postDoclavaCmds": postDoclavaCmds, |
| 1081 | }, |
| 1082 | }) |
| 1083 | } |
| 1084 | |
| 1085 | func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path, |
| 1086 | checkApiClasspath classpath, msg, opts string, output android.WritablePath) { |
| 1087 | ctx.Build(pctx, android.BuildParams{ |
| 1088 | Rule: apiCheck, |
| 1089 | Description: "Doclava Check API", |
| 1090 | Output: output, |
| 1091 | Inputs: nil, |
| 1092 | Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile}, |
| 1093 | checkApiClasspath...), |
| 1094 | Args: map[string]string{ |
| 1095 | "msg": msg, |
| 1096 | "classpath": checkApiClasspath.FormJavaClassPath(""), |
| 1097 | "opts": opts, |
| 1098 | "apiFile": apiFile.String(), |
| 1099 | "apiFileToCheck": d.apiFile.String(), |
| 1100 | "removedApiFile": removedApiFile.String(), |
| 1101 | "removedApiFileToCheck": d.removedApiFile.String(), |
| 1102 | }, |
| 1103 | }) |
| 1104 | } |
| 1105 | |
| 1106 | func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths, |
| 1107 | classpathArgs, opts string) { |
| 1108 | ctx.Build(pctx, android.BuildParams{ |
| 1109 | Rule: dokka, |
| 1110 | Description: "Dokka", |
| 1111 | Output: d.Javadoc.stubsSrcJar, |
| 1112 | Inputs: d.Javadoc.srcFiles, |
| 1113 | Implicits: implicits, |
| 1114 | Args: map[string]string{ |
| 1115 | "outDir": android.PathForModuleOut(ctx, "out").String(), |
| 1116 | "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(), |
| 1117 | "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(), |
| 1118 | "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "), |
| 1119 | "classpathArgs": classpathArgs, |
| 1120 | "opts": opts, |
| 1121 | "docZip": d.Javadoc.docZip.String(), |
| 1122 | }, |
| 1123 | }) |
| 1124 | } |
| 1125 | |
| 1126 | func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1127 | deps := d.Javadoc.collectDeps(ctx) |
| 1128 | |
| 1129 | jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar") |
| 1130 | doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar") |
| 1131 | java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME") |
| 1132 | checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")} |
| 1133 | |
| 1134 | var implicits android.Paths |
| 1135 | implicits = append(implicits, d.Javadoc.srcJars...) |
| 1136 | implicits = append(implicits, d.Javadoc.argFiles...) |
| 1137 | |
| 1138 | var implicitOutputs android.WritablePaths |
| 1139 | implicitOutputs = append(implicitOutputs, d.Javadoc.docZip) |
| 1140 | for _, o := range d.Javadoc.properties.Out { |
| 1141 | implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o)) |
| 1142 | } |
| 1143 | |
| 1144 | flags, err := d.initBuilderFlags(ctx, &implicits, deps) |
| 1145 | if err != nil { |
| 1146 | return |
| 1147 | } |
| 1148 | |
| 1149 | flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs) |
| 1150 | if Bool(d.properties.Dokka_enabled) { |
| 1151 | d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args) |
| 1152 | } else { |
| 1153 | flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava) |
| 1154 | flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits) |
| 1155 | d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs, |
| 1156 | flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args, |
| 1157 | flags.postDoclavaCmds) |
| 1158 | } |
| 1159 | |
| 1160 | if apiCheckEnabled(d.properties.Check_api.Current, "current") && |
| 1161 | !ctx.Config().IsPdkBuild() { |
| 1162 | apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file), |
| 1163 | "check_api.current.api_file") |
| 1164 | removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file), |
| 1165 | "check_api.current_removed_api_file") |
| 1166 | |
| 1167 | d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp") |
| 1168 | d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath, |
| 1169 | fmt.Sprintf(`\n******************************\n`+ |
| 1170 | `You have tried to change the API from what has been previously approved.\n\n`+ |
| 1171 | `To make these errors go away, you have two choices:\n`+ |
| 1172 | ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+ |
| 1173 | ` errors above.\n\n`+ |
| 1174 | ` 2. You can update current.txt by executing the following command:\n`+ |
| 1175 | ` make %s-update-current-api\n\n`+ |
| 1176 | ` To submit the revised current.txt to the main Android repository,\n`+ |
| 1177 | ` you will need approval.\n`+ |
| 1178 | `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args), |
| 1179 | d.checkCurrentApiTimestamp) |
| 1180 | |
| 1181 | d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp") |
| 1182 | transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile, |
| 1183 | d.updateCurrentApiTimestamp) |
| 1184 | } |
| 1185 | |
| 1186 | if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") && |
| 1187 | !ctx.Config().IsPdkBuild() { |
| 1188 | apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file), |
| 1189 | "check_api.last_released.api_file") |
| 1190 | removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file), |
| 1191 | "check_api.last_released.removed_api_file") |
| 1192 | |
| 1193 | d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp") |
| 1194 | d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath, |
| 1195 | `\n******************************\n`+ |
| 1196 | `You have tried to change the API from what has been previously released in\n`+ |
| 1197 | `an SDK. Please fix the errors listed above.\n`+ |
| 1198 | `******************************\n`, String(d.properties.Check_api.Last_released.Args), |
| 1199 | d.checkLastReleasedApiTimestamp) |
| 1200 | } |
| 1201 | } |
| 1202 | |
| 1203 | // |
| 1204 | // Droidstubs |
| 1205 | // |
| 1206 | type Droidstubs struct { |
| 1207 | Javadoc |
| 1208 | |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1209 | properties DroidstubsProperties |
| 1210 | apiFile android.WritablePath |
| 1211 | apiXmlFile android.WritablePath |
| 1212 | lastReleasedApiXmlFile android.WritablePath |
| 1213 | dexApiFile android.WritablePath |
| 1214 | privateApiFile android.WritablePath |
| 1215 | privateDexApiFile android.WritablePath |
| 1216 | removedApiFile android.WritablePath |
| 1217 | removedDexApiFile android.WritablePath |
| 1218 | apiMappingFile android.WritablePath |
| 1219 | exactApiFile android.WritablePath |
Nan Zhang | 199645c | 2018-09-19 12:40:06 -0700 | [diff] [blame] | 1220 | proguardFile android.WritablePath |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1221 | |
| 1222 | checkCurrentApiTimestamp android.WritablePath |
| 1223 | updateCurrentApiTimestamp android.WritablePath |
| 1224 | checkLastReleasedApiTimestamp android.WritablePath |
| 1225 | |
| 1226 | annotationsZip android.WritablePath |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1227 | apiVersionsXml android.WritablePath |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1228 | |
| 1229 | apiFilePath android.Path |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1230 | |
| 1231 | jdiffDocZip android.WritablePath |
| 1232 | jdiffStubsSrcJar android.WritablePath |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1233 | } |
| 1234 | |
| 1235 | func DroidstubsFactory() android.Module { |
| 1236 | module := &Droidstubs{} |
| 1237 | |
| 1238 | module.AddProperties(&module.properties, |
| 1239 | &module.Javadoc.properties) |
| 1240 | |
| 1241 | InitDroiddocModule(module, android.HostAndDeviceSupported) |
| 1242 | return module |
| 1243 | } |
| 1244 | |
| 1245 | func DroidstubsHostFactory() android.Module { |
| 1246 | module := &Droidstubs{} |
| 1247 | |
| 1248 | module.AddProperties(&module.properties, |
| 1249 | &module.Javadoc.properties) |
| 1250 | |
| 1251 | InitDroiddocModule(module, android.HostSupported) |
| 1252 | return module |
| 1253 | } |
| 1254 | |
| 1255 | func (d *Droidstubs) ApiFilePath() android.Path { |
| 1256 | return d.apiFilePath |
| 1257 | } |
| 1258 | |
| 1259 | func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 1260 | d.Javadoc.addDeps(ctx) |
| 1261 | |
| 1262 | if apiCheckEnabled(d.properties.Check_api.Current, "current") { |
| 1263 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file) |
| 1264 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file) |
| 1265 | } |
| 1266 | |
| 1267 | if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") { |
| 1268 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file) |
| 1269 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file) |
| 1270 | } |
| 1271 | |
| 1272 | if String(d.properties.Previous_api) != "" { |
| 1273 | android.ExtractSourceDeps(ctx, d.properties.Previous_api) |
| 1274 | } |
| 1275 | |
| 1276 | if len(d.properties.Merge_annotations_dirs) != 0 { |
| 1277 | for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs { |
| 1278 | ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir) |
| 1279 | } |
| 1280 | } |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1281 | |
Pete Gillin | 7716790 | 2018-09-19 18:16:26 +0100 | [diff] [blame] | 1282 | if len(d.properties.Merge_inclusion_annotations_dirs) != 0 { |
| 1283 | for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs { |
| 1284 | ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir) |
| 1285 | } |
| 1286 | } |
| 1287 | |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1288 | if len(d.properties.Api_levels_annotations_dirs) != 0 { |
| 1289 | for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs { |
| 1290 | ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir) |
| 1291 | } |
| 1292 | } |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1293 | } |
| 1294 | |
| 1295 | func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths, |
| 1296 | deps deps) (droiddocBuilderFlags, error) { |
| 1297 | var flags droiddocBuilderFlags |
| 1298 | |
| 1299 | *implicits = append(*implicits, deps.bootClasspath...) |
| 1300 | *implicits = append(*implicits, deps.classpath...) |
| 1301 | |
| 1302 | // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled |
| 1303 | // since it doesn't support system modules yet. |
| 1304 | if len(deps.bootClasspath.Strings()) > 0 { |
| 1305 | // For OpenJDK 8 we can use -bootclasspath to define the core libraries code. |
| 1306 | flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath") |
| 1307 | } |
| 1308 | flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath") |
| 1309 | |
Sundong Ahn | 56dce44 | 2018-10-05 18:41:09 +0900 | [diff] [blame^] | 1310 | flags.sourcepathArgs = "-sourcepath \"" + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + "\"" |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1311 | return flags, nil |
| 1312 | } |
| 1313 | |
| 1314 | func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext, |
| 1315 | implicitOutputs *android.WritablePaths) string { |
| 1316 | var metalavaFlags string |
| 1317 | if apiCheckEnabled(d.properties.Check_api.Current, "current") || |
| 1318 | apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") || |
| 1319 | String(d.properties.Api_filename) != "" { |
| 1320 | d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt") |
| 1321 | metalavaFlags = metalavaFlags + " --api " + d.apiFile.String() |
| 1322 | *implicitOutputs = append(*implicitOutputs, d.apiFile) |
| 1323 | d.apiFilePath = d.apiFile |
| 1324 | } |
| 1325 | |
| 1326 | if apiCheckEnabled(d.properties.Check_api.Current, "current") || |
| 1327 | apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") || |
| 1328 | String(d.properties.Removed_api_filename) != "" { |
| 1329 | d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt") |
| 1330 | metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String() |
| 1331 | *implicitOutputs = append(*implicitOutputs, d.removedApiFile) |
| 1332 | } |
| 1333 | |
| 1334 | if String(d.properties.Private_api_filename) != "" { |
| 1335 | d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename)) |
| 1336 | metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String() |
| 1337 | *implicitOutputs = append(*implicitOutputs, d.privateApiFile) |
| 1338 | } |
| 1339 | |
| 1340 | if String(d.properties.Dex_api_filename) != "" { |
| 1341 | d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename)) |
| 1342 | metalavaFlags += " --dex-api " + d.dexApiFile.String() |
| 1343 | *implicitOutputs = append(*implicitOutputs, d.dexApiFile) |
| 1344 | } |
| 1345 | |
| 1346 | if String(d.properties.Private_dex_api_filename) != "" { |
| 1347 | d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename)) |
| 1348 | metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String() |
| 1349 | *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile) |
| 1350 | } |
| 1351 | |
| 1352 | if String(d.properties.Removed_dex_api_filename) != "" { |
| 1353 | d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename)) |
| 1354 | metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String() |
| 1355 | *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile) |
| 1356 | } |
| 1357 | |
| 1358 | if String(d.properties.Exact_api_filename) != "" { |
| 1359 | d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename)) |
| 1360 | metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String() |
| 1361 | *implicitOutputs = append(*implicitOutputs, d.exactApiFile) |
| 1362 | } |
| 1363 | |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1364 | if String(d.properties.Dex_mapping_filename) != "" { |
| 1365 | d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename)) |
| 1366 | metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String() |
| 1367 | *implicitOutputs = append(*implicitOutputs, d.apiMappingFile) |
| 1368 | } |
| 1369 | |
Nan Zhang | 199645c | 2018-09-19 12:40:06 -0700 | [diff] [blame] | 1370 | if String(d.properties.Proguard_filename) != "" { |
| 1371 | d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename)) |
| 1372 | metalavaFlags += " --proguard " + d.proguardFile.String() |
| 1373 | *implicitOutputs = append(*implicitOutputs, d.proguardFile) |
| 1374 | } |
| 1375 | |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1376 | if Bool(d.properties.Write_sdk_values) { |
| 1377 | metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String() |
| 1378 | } |
| 1379 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1380 | if Bool(d.properties.Create_doc_stubs) { |
| 1381 | metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String() |
| 1382 | } else { |
| 1383 | metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String() |
| 1384 | } |
| 1385 | |
| 1386 | return metalavaFlags |
| 1387 | } |
| 1388 | |
| 1389 | func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext, |
| 1390 | implicits *android.Paths, implicitOutputs *android.WritablePaths) string { |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1391 | var flags string |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1392 | if Bool(d.properties.Annotations_enabled) { |
| 1393 | if String(d.properties.Previous_api) == "" { |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1394 | ctx.PropertyErrorf("metalava_previous_api", |
| 1395 | "has to be non-empty if annotations was enabled!") |
| 1396 | } |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1397 | previousApi := ctx.ExpandSource(String(d.properties.Previous_api), |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 1398 | "metalava_previous_api") |
| 1399 | *implicits = append(*implicits, previousApi) |
Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 1400 | |
Nan Zhang | d05a436 | 2018-08-15 13:28:54 -0700 | [diff] [blame] | 1401 | flags += " --include-annotations --migrate-nullness " + previousApi.String() |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1402 | |
| 1403 | d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip") |
| 1404 | *implicitOutputs = append(*implicitOutputs, d.annotationsZip) |
| 1405 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1406 | flags += " --extract-annotations " + d.annotationsZip.String() |
| 1407 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1408 | if len(d.properties.Merge_annotations_dirs) == 0 { |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1409 | ctx.PropertyErrorf("merge_annotations_dirs", |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1410 | "has to be non-empty if annotations was enabled!") |
| 1411 | } |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1412 | ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) { |
| 1413 | if t, ok := m.(*ExportedDroiddocDir); ok { |
| 1414 | *implicits = append(*implicits, t.deps...) |
Pete Gillin | 7716790 | 2018-09-19 18:16:26 +0100 | [diff] [blame] | 1415 | flags += " --merge-qualifier-annotations " + t.dir.String() |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1416 | } else { |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1417 | ctx.PropertyErrorf("merge_annotations_dirs", |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1418 | "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m)) |
| 1419 | } |
| 1420 | }) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1421 | // TODO(tnorbye): find owners to fix these warnings when annotation was enabled. |
| 1422 | flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction " |
| 1423 | } |
Pete Gillin | 7716790 | 2018-09-19 18:16:26 +0100 | [diff] [blame] | 1424 | ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) { |
| 1425 | if t, ok := m.(*ExportedDroiddocDir); ok { |
| 1426 | *implicits = append(*implicits, t.deps...) |
| 1427 | flags += " --merge-inclusion-annotations " + t.dir.String() |
| 1428 | } else { |
| 1429 | ctx.PropertyErrorf("merge_inclusion_annotations_dirs", |
| 1430 | "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m)) |
| 1431 | } |
| 1432 | }) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1433 | |
| 1434 | return flags |
| 1435 | } |
| 1436 | |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1437 | func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext, |
| 1438 | implicits *android.Paths, implicitOutputs *android.WritablePaths) string { |
| 1439 | var flags string |
| 1440 | if Bool(d.properties.Api_levels_annotations_enabled) { |
| 1441 | d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml") |
| 1442 | *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml) |
| 1443 | |
| 1444 | if len(d.properties.Api_levels_annotations_dirs) == 0 { |
| 1445 | ctx.PropertyErrorf("api_levels_annotations_dirs", |
| 1446 | "has to be non-empty if api levels annotations was enabled!") |
| 1447 | } |
| 1448 | |
| 1449 | flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " + |
| 1450 | d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() + |
| 1451 | " --current-codename " + ctx.Config().PlatformSdkCodename() + " " |
| 1452 | |
| 1453 | ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) { |
| 1454 | if t, ok := m.(*ExportedDroiddocDir); ok { |
| 1455 | var androidJars android.Paths |
| 1456 | for _, dep := range t.deps { |
| 1457 | if strings.HasSuffix(dep.String(), "android.jar") { |
| 1458 | androidJars = append(androidJars, dep) |
| 1459 | } |
| 1460 | } |
| 1461 | *implicits = append(*implicits, androidJars...) |
| 1462 | flags += " --android-jar-pattern " + t.dir.String() + "/%/android.jar " |
| 1463 | } else { |
| 1464 | ctx.PropertyErrorf("api_levels_annotations_dirs", |
| 1465 | "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m)) |
| 1466 | } |
| 1467 | }) |
| 1468 | |
| 1469 | } |
| 1470 | |
| 1471 | return flags |
| 1472 | } |
| 1473 | |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1474 | func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths, |
| 1475 | implicitOutputs *android.WritablePaths) string { |
| 1476 | var flags string |
| 1477 | if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() { |
| 1478 | if d.apiFile.String() == "" { |
| 1479 | ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.") |
| 1480 | } |
| 1481 | |
| 1482 | d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml") |
| 1483 | *implicitOutputs = append(*implicitOutputs, d.apiXmlFile) |
| 1484 | |
| 1485 | flags = " --api-xml " + d.apiXmlFile.String() |
| 1486 | |
| 1487 | if String(d.properties.Check_api.Last_released.Api_file) == "" { |
| 1488 | ctx.PropertyErrorf("check_api.last_released.api_file", |
| 1489 | "has to be non-empty if jdiff was enabled!") |
| 1490 | } |
| 1491 | lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file), |
| 1492 | "check_api.last_released.api_file") |
| 1493 | *implicits = append(*implicits, lastReleasedApi) |
| 1494 | |
| 1495 | d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml") |
| 1496 | *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile) |
| 1497 | |
| 1498 | flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " + |
| 1499 | d.lastReleasedApiXmlFile.String() |
| 1500 | } |
| 1501 | |
| 1502 | return flags |
| 1503 | } |
| 1504 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1505 | func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths, |
| 1506 | implicitOutputs android.WritablePaths, javaVersion, |
| 1507 | bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) { |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1508 | |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1509 | ctx.Build(pctx, android.BuildParams{ |
| 1510 | Rule: metalava, |
| 1511 | Description: "Metalava", |
| 1512 | Output: d.Javadoc.stubsSrcJar, |
| 1513 | Inputs: d.Javadoc.srcFiles, |
| 1514 | Implicits: implicits, |
| 1515 | ImplicitOutputs: implicitOutputs, |
| 1516 | Args: map[string]string{ |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1517 | "outDir": android.PathForModuleOut(ctx, "out").String(), |
| 1518 | "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(), |
| 1519 | "stubsDir": android.PathForModuleOut(ctx, "stubsDir").String(), |
| 1520 | "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "), |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1521 | "javaVersion": javaVersion, |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1522 | "bootclasspathArgs": bootclasspathArgs, |
| 1523 | "classpathArgs": classpathArgs, |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1524 | "sourcepathArgs": sourcepathArgs, |
| 1525 | "opts": opts, |
Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1526 | }, |
| 1527 | }) |
| 1528 | } |
| 1529 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1530 | func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext, |
| 1531 | apiFile, removedApiFile android.Path, implicits android.Paths, |
| 1532 | javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, msg string, |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1533 | output android.WritablePath) { |
| 1534 | ctx.Build(pctx, android.BuildParams{ |
| 1535 | Rule: metalavaApiCheck, |
| 1536 | Description: "Metalava Check API", |
| 1537 | Output: output, |
| 1538 | Inputs: d.Javadoc.srcFiles, |
| 1539 | Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile}, |
| 1540 | implicits...), |
| 1541 | Args: map[string]string{ |
| 1542 | "srcJarDir": android.PathForModuleOut(ctx, "srcjars").String(), |
| 1543 | "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "), |
| 1544 | "javaVersion": javaVersion, |
| 1545 | "bootclasspathArgs": bootclasspathArgs, |
| 1546 | "classpathArgs": classpathArgs, |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1547 | "sourcepathArgs": sourcepathArgs, |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1548 | "opts": opts, |
| 1549 | "msg": msg, |
| 1550 | }, |
| 1551 | }) |
| 1552 | } |
| 1553 | |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1554 | func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths, |
| 1555 | implicitOutputs android.WritablePaths, |
| 1556 | bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) { |
| 1557 | ctx.Build(pctx, android.BuildParams{ |
| 1558 | Rule: javadoc, |
| 1559 | Description: "Jdiff", |
| 1560 | Output: d.jdiffStubsSrcJar, |
| 1561 | Inputs: d.Javadoc.srcFiles, |
| 1562 | Implicits: implicits, |
| 1563 | ImplicitOutputs: implicitOutputs, |
| 1564 | Args: map[string]string{ |
Nan Zhang | 23a1ba6 | 2018-09-19 11:19:39 -0700 | [diff] [blame] | 1565 | "outDir": android.PathForModuleOut(ctx, "jdiff-out").String(), |
| 1566 | "srcJarDir": android.PathForModuleOut(ctx, "jdiff-srcjars").String(), |
| 1567 | "stubsDir": android.PathForModuleOut(ctx, "jdiff-stubsDir").String(), |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1568 | "srcJars": strings.Join(d.Javadoc.srcJars.Strings(), " "), |
| 1569 | "opts": opts, |
| 1570 | "bootclasspathArgs": bootclasspathArgs, |
| 1571 | "classpathArgs": classpathArgs, |
| 1572 | "sourcepathArgs": sourcepathArgs, |
| 1573 | "docZip": d.jdiffDocZip.String(), |
| 1574 | }, |
| 1575 | }) |
| 1576 | } |
| 1577 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1578 | func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1579 | deps := d.Javadoc.collectDeps(ctx) |
| 1580 | |
| 1581 | javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d)) |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1582 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1583 | var implicits android.Paths |
| 1584 | implicits = append(implicits, d.Javadoc.srcJars...) |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1585 | implicits = append(implicits, d.Javadoc.argFiles...) |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1586 | |
| 1587 | var implicitOutputs android.WritablePaths |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1588 | for _, o := range d.Javadoc.properties.Out { |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1589 | implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o)) |
| 1590 | } |
| 1591 | |
| 1592 | flags, err := d.initBuilderFlags(ctx, &implicits, deps) |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1593 | metalavaCheckApiImplicits := implicits |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1594 | jdiffImplicits := implicits |
| 1595 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1596 | if err != nil { |
| 1597 | return |
| 1598 | } |
| 1599 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1600 | flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs) |
| 1601 | flags.metalavaAnnotationsFlags = d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs) |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1602 | flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs) |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1603 | flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs) |
| 1604 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1605 | if strings.Contains(d.Javadoc.args, "--generate-documentation") { |
| 1606 | // Currently Metalava have the ability to invoke Javadoc in a seperate process. |
| 1607 | // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives |
| 1608 | // "--generate-documentation" arg. This is not needed when Metalava removes this feature. |
| 1609 | d.Javadoc.args = d.Javadoc.args + " -nodocs " |
Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 1610 | } |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1611 | d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion, |
| 1612 | flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1613 | flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+ |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1614 | flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args) |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1615 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1616 | if apiCheckEnabled(d.properties.Check_api.Current, "current") && |
| 1617 | !ctx.Config().IsPdkBuild() { |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1618 | apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file), |
| 1619 | "check_api.current.api_file") |
| 1620 | removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file), |
| 1621 | "check_api.current_removed_api_file") |
| 1622 | |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1623 | d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp") |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1624 | opts := d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() + |
| 1625 | " --check-compatibility:removed:current " + removedApiFile.String() + " " |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1626 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1627 | d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits, |
| 1628 | javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, |
| 1629 | fmt.Sprintf(`\n******************************\n`+ |
| 1630 | `You have tried to change the API from what has been previously approved.\n\n`+ |
| 1631 | `To make these errors go away, you have two choices:\n`+ |
| 1632 | ` 1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+ |
| 1633 | ` errors above.\n\n`+ |
| 1634 | ` 2. You can update current.txt by executing the following command:\n`+ |
| 1635 | ` make %s-update-current-api\n\n`+ |
| 1636 | ` To submit the revised current.txt to the main Android repository,\n`+ |
| 1637 | ` you will need approval.\n`+ |
| 1638 | `******************************\n`, ctx.ModuleName()), |
| 1639 | d.checkCurrentApiTimestamp) |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1640 | |
| 1641 | d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp") |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1642 | transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile, |
| 1643 | d.updateCurrentApiTimestamp) |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1644 | } |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1645 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1646 | if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") && |
| 1647 | !ctx.Config().IsPdkBuild() { |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1648 | apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file), |
| 1649 | "check_api.last_released.api_file") |
| 1650 | removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file), |
| 1651 | "check_api.last_released.removed_api_file") |
| 1652 | |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1653 | d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp") |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1654 | opts := d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() + |
| 1655 | " --check-compatibility:removed:released " + removedApiFile.String() + " " |
Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1656 | |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1657 | d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits, |
| 1658 | javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, |
| 1659 | `\n******************************\n`+ |
| 1660 | `You have tried to change the API from what has been previously released in\n`+ |
| 1661 | `an SDK. Please fix the errors listed above.\n`+ |
| 1662 | `******************************\n`, |
| 1663 | d.checkLastReleasedApiTimestamp) |
Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1664 | } |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1665 | |
| 1666 | if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() { |
| 1667 | |
Nan Zhang | 86b0620 | 2018-09-21 17:09:21 -0700 | [diff] [blame] | 1668 | // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below |
| 1669 | // since there's cron job downstream that fetch this .zip file periodically. |
| 1670 | // See b/116221385 for reference. |
Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1671 | d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip") |
| 1672 | d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar") |
| 1673 | |
| 1674 | var jdiffImplicitOutputs android.WritablePaths |
| 1675 | jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip) |
| 1676 | |
| 1677 | jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar") |
| 1678 | jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...) |
| 1679 | |
| 1680 | opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " + |
| 1681 | "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " + |
| 1682 | "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) + |
| 1683 | " -newapidir " + filepath.Dir(d.apiXmlFile.String()) + |
| 1684 | " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) + |
| 1685 | " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String()) |
| 1686 | |
| 1687 | d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs, |
| 1688 | flags.sourcepathArgs, opts) |
| 1689 | } |
Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1690 | } |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1691 | |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1692 | // |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1693 | // Exported Droiddoc Directory |
Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1694 | // |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1695 | var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"} |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1696 | var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"} |
Pete Gillin | 7716790 | 2018-09-19 18:16:26 +0100 | [diff] [blame] | 1697 | var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"} |
Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1698 | var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"} |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1699 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1700 | type ExportedDroiddocDirProperties struct { |
| 1701 | // path to the directory containing Droiddoc related files. |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1702 | Path *string |
| 1703 | } |
| 1704 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1705 | type ExportedDroiddocDir struct { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1706 | android.ModuleBase |
| 1707 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1708 | properties ExportedDroiddocDirProperties |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1709 | |
| 1710 | deps android.Paths |
| 1711 | dir android.Path |
| 1712 | } |
| 1713 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1714 | func ExportedDroiddocDirFactory() android.Module { |
| 1715 | module := &ExportedDroiddocDir{} |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1716 | module.AddProperties(&module.properties) |
| 1717 | android.InitAndroidModule(module) |
| 1718 | return module |
| 1719 | } |
| 1720 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1721 | func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {} |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1722 | |
Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1723 | func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1724 | path := android.PathForModuleSrc(ctx, String(d.properties.Path)) |
| 1725 | d.dir = path |
| 1726 | d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil) |
| 1727 | } |
Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 1728 | |
| 1729 | // |
| 1730 | // Defaults |
| 1731 | // |
| 1732 | type DocDefaults struct { |
| 1733 | android.ModuleBase |
| 1734 | android.DefaultsModuleBase |
| 1735 | } |
| 1736 | |
| 1737 | func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { |
| 1738 | } |
| 1739 | |
| 1740 | func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) { |
| 1741 | } |
| 1742 | |
| 1743 | func DocDefaultsFactory() android.Module { |
| 1744 | module := &DocDefaults{} |
| 1745 | |
| 1746 | module.AddProperties( |
| 1747 | &JavadocProperties{}, |
| 1748 | &DroiddocProperties{}, |
| 1749 | ) |
| 1750 | |
| 1751 | android.InitDefaultsModule(module) |
| 1752 | |
| 1753 | return module |
| 1754 | } |
Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1755 | |
| 1756 | func StubsDefaultsFactory() android.Module { |
| 1757 | module := &DocDefaults{} |
| 1758 | |
| 1759 | module.AddProperties( |
| 1760 | &JavadocProperties{}, |
| 1761 | &DroidstubsProperties{}, |
| 1762 | ) |
| 1763 | |
| 1764 | android.InitDefaultsModule(module) |
| 1765 | |
| 1766 | return module |
| 1767 | } |