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