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