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