| 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 | 
| Nan Zhang | dee152b | 2018-12-26 16:06:37 -0800 | [diff] [blame] | 403 | metalavaMergeAnnoDirFlags         string | 
| Neil Fuller | b2f14ec | 2018-10-21 22:13:19 +0100 | [diff] [blame] | 404 | metalavaInclusionAnnotationsFlags string | 
| Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 405 | metalavaApiLevelsAnnotationsFlags string | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 406 |  | 
| Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 407 | metalavaApiToXmlFlags string | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 408 | } | 
|  | 409 |  | 
|  | 410 | func InitDroiddocModule(module android.DefaultableModule, hod android.HostOrDeviceSupported) { | 
|  | 411 | android.InitAndroidArchModule(module, hod, android.MultilibCommon) | 
|  | 412 | android.InitDefaultableModule(module) | 
|  | 413 | } | 
|  | 414 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 415 | func apiCheckEnabled(apiToCheck ApiToCheck, apiVersionTag string) bool { | 
|  | 416 | if String(apiToCheck.Api_file) != "" && String(apiToCheck.Removed_api_file) != "" { | 
|  | 417 | return true | 
|  | 418 | } else if String(apiToCheck.Api_file) != "" { | 
|  | 419 | panic("for " + apiVersionTag + " removed_api_file has to be non-empty!") | 
|  | 420 | } else if String(apiToCheck.Removed_api_file) != "" { | 
|  | 421 | panic("for " + apiVersionTag + " api_file has to be non-empty!") | 
|  | 422 | } | 
|  | 423 |  | 
|  | 424 | return false | 
|  | 425 | } | 
|  | 426 |  | 
|  | 427 | type ApiFilePath interface { | 
|  | 428 | ApiFilePath() android.Path | 
|  | 429 | } | 
|  | 430 |  | 
|  | 431 | func transformUpdateApi(ctx android.ModuleContext, destApiFile, destRemovedApiFile, | 
|  | 432 | srcApiFile, srcRemovedApiFile android.Path, output android.WritablePath) { | 
|  | 433 | ctx.Build(pctx, android.BuildParams{ | 
|  | 434 | Rule:        updateApi, | 
|  | 435 | Description: "Update API", | 
|  | 436 | Output:      output, | 
|  | 437 | Implicits: append(android.Paths{}, srcApiFile, srcRemovedApiFile, | 
|  | 438 | destApiFile, destRemovedApiFile), | 
|  | 439 | Args: map[string]string{ | 
|  | 440 | "destApiFile":        destApiFile.String(), | 
|  | 441 | "srcApiFile":         srcApiFile.String(), | 
|  | 442 | "destRemovedApiFile": destRemovedApiFile.String(), | 
|  | 443 | "srcRemovedApiFile":  srcRemovedApiFile.String(), | 
|  | 444 | }, | 
|  | 445 | }) | 
|  | 446 | } | 
|  | 447 |  | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 448 | // | 
|  | 449 | // Javadoc | 
|  | 450 | // | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 451 | type Javadoc struct { | 
|  | 452 | android.ModuleBase | 
|  | 453 | android.DefaultableModuleBase | 
|  | 454 |  | 
|  | 455 | properties JavadocProperties | 
|  | 456 |  | 
|  | 457 | srcJars     android.Paths | 
|  | 458 | srcFiles    android.Paths | 
|  | 459 | sourcepaths android.Paths | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 460 | argFiles    android.Paths | 
|  | 461 |  | 
|  | 462 | args string | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 463 |  | 
| Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 464 | docZip      android.WritablePath | 
|  | 465 | stubsSrcJar android.WritablePath | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 466 | } | 
|  | 467 |  | 
| Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 468 | func (j *Javadoc) Srcs() android.Paths { | 
|  | 469 | return android.Paths{j.stubsSrcJar} | 
|  | 470 | } | 
|  | 471 |  | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 472 | func JavadocFactory() android.Module { | 
|  | 473 | module := &Javadoc{} | 
|  | 474 |  | 
|  | 475 | module.AddProperties(&module.properties) | 
|  | 476 |  | 
|  | 477 | InitDroiddocModule(module, android.HostAndDeviceSupported) | 
|  | 478 | return module | 
|  | 479 | } | 
|  | 480 |  | 
|  | 481 | func JavadocHostFactory() android.Module { | 
|  | 482 | module := &Javadoc{} | 
|  | 483 |  | 
|  | 484 | module.AddProperties(&module.properties) | 
|  | 485 |  | 
|  | 486 | InitDroiddocModule(module, android.HostSupported) | 
|  | 487 | return module | 
|  | 488 | } | 
|  | 489 |  | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 490 | var _ android.SourceFileProducer = (*Javadoc)(nil) | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 491 |  | 
| Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 492 | func (j *Javadoc) sdkVersion() string { | 
|  | 493 | return String(j.properties.Sdk_version) | 
|  | 494 | } | 
|  | 495 |  | 
|  | 496 | func (j *Javadoc) minSdkVersion() string { | 
|  | 497 | return j.sdkVersion() | 
|  | 498 | } | 
|  | 499 |  | 
| Dan Willemsen | 419290a | 2018-10-31 15:28:47 -0700 | [diff] [blame] | 500 | func (j *Javadoc) targetSdkVersion() string { | 
|  | 501 | return j.sdkVersion() | 
|  | 502 | } | 
|  | 503 |  | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 504 | func (j *Javadoc) addDeps(ctx android.BottomUpMutatorContext) { | 
|  | 505 | if ctx.Device() { | 
| Nan Zhang | 5994b62 | 2018-09-21 16:39:51 -0700 | [diff] [blame] | 506 | if !Bool(j.properties.No_standard_libs) { | 
|  | 507 | sdkDep := decodeSdkDep(ctx, sdkContext(j)) | 
|  | 508 | if sdkDep.useDefaultLibs { | 
|  | 509 | ctx.AddVariationDependencies(nil, bootClasspathTag, config.DefaultBootclasspathLibraries...) | 
|  | 510 | if ctx.Config().TargetOpenJDK9() { | 
|  | 511 | ctx.AddVariationDependencies(nil, systemModulesTag, config.DefaultSystemModules) | 
|  | 512 | } | 
|  | 513 | if !Bool(j.properties.No_framework_libs) { | 
|  | 514 | ctx.AddVariationDependencies(nil, libTag, config.DefaultLibraries...) | 
|  | 515 | } | 
|  | 516 | } else if sdkDep.useModule { | 
|  | 517 | if ctx.Config().TargetOpenJDK9() { | 
|  | 518 | ctx.AddVariationDependencies(nil, systemModulesTag, sdkDep.systemModules) | 
|  | 519 | } | 
|  | 520 | ctx.AddVariationDependencies(nil, bootClasspathTag, sdkDep.modules...) | 
| Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 521 | } | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 522 | } | 
|  | 523 | } | 
|  | 524 |  | 
| Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 525 | ctx.AddVariationDependencies(nil, libTag, j.properties.Libs...) | 
| Colin Cross | a1ce2a0 | 2018-06-20 15:19:39 -0700 | [diff] [blame] | 526 | if j.properties.Srcs_lib != nil { | 
| Colin Cross | 42d48b7 | 2018-08-29 14:10:52 -0700 | [diff] [blame] | 527 | ctx.AddVariationDependencies(nil, srcsLibTag, *j.properties.Srcs_lib) | 
| Colin Cross | a1ce2a0 | 2018-06-20 15:19:39 -0700 | [diff] [blame] | 528 | } | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 529 |  | 
|  | 530 | android.ExtractSourcesDeps(ctx, j.properties.Srcs) | 
|  | 531 |  | 
|  | 532 | // exclude_srcs may contain filegroup or genrule. | 
|  | 533 | android.ExtractSourcesDeps(ctx, j.properties.Exclude_srcs) | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 534 |  | 
|  | 535 | // arg_files may contains filegroup or genrule. | 
|  | 536 | android.ExtractSourcesDeps(ctx, j.properties.Arg_files) | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 537 | } | 
|  | 538 |  | 
| Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 539 | func (j *Javadoc) genWhitelistPathPrefixes(whitelistPathPrefixes map[string]bool) { | 
|  | 540 | for _, dir := range j.properties.Srcs_lib_whitelist_dirs { | 
|  | 541 | for _, pkg := range j.properties.Srcs_lib_whitelist_pkgs { | 
| Jiyong Park | 82484c0 | 2018-04-23 21:41:26 +0900 | [diff] [blame] | 542 | // convert foo.bar.baz to foo/bar/baz | 
|  | 543 | pkgAsPath := filepath.Join(strings.Split(pkg, ".")...) | 
|  | 544 | prefix := filepath.Join(dir, pkgAsPath) | 
| Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 545 | if _, found := whitelistPathPrefixes[prefix]; !found { | 
|  | 546 | whitelistPathPrefixes[prefix] = true | 
|  | 547 | } | 
|  | 548 | } | 
|  | 549 | } | 
|  | 550 | } | 
|  | 551 |  | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 552 | func (j *Javadoc) collectAidlFlags(ctx android.ModuleContext, deps deps) droiddocBuilderFlags { | 
|  | 553 | var flags droiddocBuilderFlags | 
| Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 554 |  | 
|  | 555 | // aidl flags. | 
|  | 556 | aidlFlags := j.aidlFlags(ctx, deps.aidlPreprocess, deps.aidlIncludeDirs) | 
|  | 557 | if len(aidlFlags) > 0 { | 
|  | 558 | // optimization. | 
|  | 559 | ctx.Variable(pctx, "aidlFlags", strings.Join(aidlFlags, " ")) | 
|  | 560 | flags.aidlFlags = "$aidlFlags" | 
|  | 561 | } | 
|  | 562 |  | 
|  | 563 | return flags | 
|  | 564 | } | 
|  | 565 |  | 
|  | 566 | func (j *Javadoc) aidlFlags(ctx android.ModuleContext, aidlPreprocess android.OptionalPath, | 
|  | 567 | aidlIncludeDirs android.Paths) []string { | 
|  | 568 |  | 
|  | 569 | aidlIncludes := android.PathsForModuleSrc(ctx, j.properties.Aidl.Local_include_dirs) | 
|  | 570 | aidlIncludes = append(aidlIncludes, android.PathsForSource(ctx, j.properties.Aidl.Include_dirs)...) | 
|  | 571 |  | 
|  | 572 | var flags []string | 
|  | 573 | if aidlPreprocess.Valid() { | 
|  | 574 | flags = append(flags, "-p"+aidlPreprocess.String()) | 
|  | 575 | } else { | 
|  | 576 | flags = append(flags, android.JoinWithPrefix(aidlIncludeDirs.Strings(), "-I")) | 
|  | 577 | } | 
|  | 578 |  | 
|  | 579 | flags = append(flags, android.JoinWithPrefix(aidlIncludes.Strings(), "-I")) | 
|  | 580 | flags = append(flags, "-I"+android.PathForModuleSrc(ctx).String()) | 
|  | 581 | if src := android.ExistentPathForSource(ctx, ctx.ModuleDir(), "src"); src.Valid() { | 
|  | 582 | flags = append(flags, "-I"+src.String()) | 
|  | 583 | } | 
|  | 584 |  | 
|  | 585 | return flags | 
|  | 586 | } | 
|  | 587 |  | 
|  | 588 | func (j *Javadoc) genSources(ctx android.ModuleContext, srcFiles android.Paths, | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 589 | flags droiddocBuilderFlags) android.Paths { | 
| Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 590 |  | 
|  | 591 | outSrcFiles := make(android.Paths, 0, len(srcFiles)) | 
|  | 592 |  | 
|  | 593 | for _, srcFile := range srcFiles { | 
|  | 594 | switch srcFile.Ext() { | 
|  | 595 | case ".aidl": | 
|  | 596 | javaFile := genAidl(ctx, srcFile, flags.aidlFlags) | 
|  | 597 | outSrcFiles = append(outSrcFiles, javaFile) | 
|  | 598 | default: | 
|  | 599 | outSrcFiles = append(outSrcFiles, srcFile) | 
|  | 600 | } | 
|  | 601 | } | 
|  | 602 |  | 
|  | 603 | return outSrcFiles | 
|  | 604 | } | 
|  | 605 |  | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 606 | func (j *Javadoc) collectDeps(ctx android.ModuleContext) deps { | 
|  | 607 | var deps deps | 
|  | 608 |  | 
| Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 609 | sdkDep := decodeSdkDep(ctx, sdkContext(j)) | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 610 | if sdkDep.invalidVersion { | 
| Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 611 | ctx.AddMissingDependencies(sdkDep.modules) | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 612 | } else if sdkDep.useFiles { | 
| Colin Cross | 86a60ae | 2018-05-29 14:44:55 -0700 | [diff] [blame] | 613 | deps.bootClasspath = append(deps.bootClasspath, sdkDep.jars...) | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 614 | } | 
|  | 615 |  | 
|  | 616 | ctx.VisitDirectDeps(func(module android.Module) { | 
|  | 617 | otherName := ctx.OtherModuleName(module) | 
|  | 618 | tag := ctx.OtherModuleDependencyTag(module) | 
|  | 619 |  | 
| Colin Cross | 2d24c1b | 2018-05-23 10:59:18 -0700 | [diff] [blame] | 620 | switch tag { | 
|  | 621 | case bootClasspathTag: | 
|  | 622 | if dep, ok := module.(Dependency); ok { | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 623 | deps.bootClasspath = append(deps.bootClasspath, dep.ImplementationJars()...) | 
| Colin Cross | 2d24c1b | 2018-05-23 10:59:18 -0700 | [diff] [blame] | 624 | } else { | 
|  | 625 | panic(fmt.Errorf("unknown dependency %q for %q", otherName, ctx.ModuleName())) | 
|  | 626 | } | 
|  | 627 | case libTag: | 
|  | 628 | switch dep := module.(type) { | 
|  | 629 | case Dependency: | 
| Sundong Ahn | ba49360 | 2018-11-20 17:36:35 +0900 | [diff] [blame] | 630 | deps.classpath = append(deps.classpath, dep.HeaderJars()...) | 
| Colin Cross | 2d24c1b | 2018-05-23 10:59:18 -0700 | [diff] [blame] | 631 | case SdkLibraryDependency: | 
| Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 632 | sdkVersion := j.sdkVersion() | 
| Jiyong Park | c678ad3 | 2018-04-10 13:07:10 +0900 | [diff] [blame] | 633 | linkType := javaSdk | 
|  | 634 | if strings.HasPrefix(sdkVersion, "system_") || strings.HasPrefix(sdkVersion, "test_") { | 
|  | 635 | linkType = javaSystem | 
|  | 636 | } else if sdkVersion == "" { | 
|  | 637 | linkType = javaPlatform | 
|  | 638 | } | 
| Sundong Ahn | 241cd37 | 2018-07-13 16:16:44 +0900 | [diff] [blame] | 639 | deps.classpath = append(deps.classpath, dep.ImplementationJars(linkType)...) | 
| Colin Cross | 2d24c1b | 2018-05-23 10:59:18 -0700 | [diff] [blame] | 640 | case android.SourceFileProducer: | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 641 | checkProducesJars(ctx, dep) | 
|  | 642 | deps.classpath = append(deps.classpath, dep.Srcs()...) | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 643 | default: | 
|  | 644 | ctx.ModuleErrorf("depends on non-java module %q", otherName) | 
|  | 645 | } | 
| Colin Cross | a1ce2a0 | 2018-06-20 15:19:39 -0700 | [diff] [blame] | 646 | case srcsLibTag: | 
|  | 647 | switch dep := module.(type) { | 
|  | 648 | case Dependency: | 
|  | 649 | srcs := dep.(SrcDependency).CompiledSrcs() | 
|  | 650 | whitelistPathPrefixes := make(map[string]bool) | 
|  | 651 | j.genWhitelistPathPrefixes(whitelistPathPrefixes) | 
|  | 652 | for _, src := range srcs { | 
|  | 653 | if _, ok := src.(android.WritablePath); ok { // generated sources | 
|  | 654 | deps.srcs = append(deps.srcs, src) | 
|  | 655 | } else { // select source path for documentation based on whitelist path prefixs. | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 656 | for k := range whitelistPathPrefixes { | 
| Colin Cross | a1ce2a0 | 2018-06-20 15:19:39 -0700 | [diff] [blame] | 657 | if strings.HasPrefix(src.Rel(), k) { | 
|  | 658 | deps.srcs = append(deps.srcs, src) | 
|  | 659 | break | 
|  | 660 | } | 
|  | 661 | } | 
|  | 662 | } | 
|  | 663 | } | 
|  | 664 | deps.srcJars = append(deps.srcJars, dep.(SrcDependency).CompiledSrcJars()...) | 
|  | 665 | default: | 
|  | 666 | ctx.ModuleErrorf("depends on non-java module %q", otherName) | 
|  | 667 | } | 
| Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 668 | case systemModulesTag: | 
|  | 669 | if deps.systemModules != nil { | 
|  | 670 | panic("Found two system module dependencies") | 
|  | 671 | } | 
|  | 672 | sm := module.(*SystemModules) | 
|  | 673 | if sm.outputFile == nil { | 
|  | 674 | panic("Missing directory for system module dependency") | 
|  | 675 | } | 
|  | 676 | deps.systemModules = sm.outputFile | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 677 | } | 
|  | 678 | }) | 
|  | 679 | // do not pass exclude_srcs directly when expanding srcFiles since exclude_srcs | 
|  | 680 | // may contain filegroup or genrule. | 
|  | 681 | srcFiles := ctx.ExpandSources(j.properties.Srcs, j.properties.Exclude_srcs) | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 682 | flags := j.collectAidlFlags(ctx, deps) | 
| Jiyong Park | 1e44068 | 2018-05-23 18:42:04 +0900 | [diff] [blame] | 683 | srcFiles = j.genSources(ctx, srcFiles, flags) | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 684 |  | 
|  | 685 | // srcs may depend on some genrule output. | 
|  | 686 | j.srcJars = srcFiles.FilterByExt(".srcjar") | 
| Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 687 | j.srcJars = append(j.srcJars, deps.srcJars...) | 
|  | 688 |  | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 689 | j.srcFiles = srcFiles.FilterOutByExt(".srcjar") | 
| Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 690 | j.srcFiles = append(j.srcFiles, deps.srcs...) | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 691 |  | 
|  | 692 | j.docZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"docs.zip") | 
| Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 693 | j.stubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"stubs.srcjar") | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 694 |  | 
| Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 695 | if j.properties.Local_sourcepaths == nil && len(j.srcFiles) > 0 { | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 696 | j.properties.Local_sourcepaths = append(j.properties.Local_sourcepaths, ".") | 
|  | 697 | } | 
|  | 698 | j.sourcepaths = android.PathsForModuleSrc(ctx, j.properties.Local_sourcepaths) | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 699 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 700 | j.argFiles = ctx.ExpandSources(j.properties.Arg_files, nil) | 
|  | 701 | argFilesMap := map[string]android.Path{} | 
|  | 702 |  | 
|  | 703 | for _, f := range j.argFiles { | 
|  | 704 | if _, exists := argFilesMap[f.Rel()]; !exists { | 
|  | 705 | argFilesMap[f.Rel()] = f | 
|  | 706 | } else { | 
|  | 707 | ctx.ModuleErrorf("multiple arg_files for %q, %q and %q", | 
|  | 708 | f, argFilesMap[f.Rel()], f.Rel()) | 
|  | 709 | } | 
|  | 710 | } | 
|  | 711 |  | 
|  | 712 | var err error | 
|  | 713 | j.args, err = android.Expand(String(j.properties.Args), func(name string) (string, error) { | 
|  | 714 | if strings.HasPrefix(name, "location ") { | 
|  | 715 | label := strings.TrimSpace(strings.TrimPrefix(name, "location ")) | 
|  | 716 | if f, ok := argFilesMap[label]; ok { | 
|  | 717 | return f.String(), nil | 
|  | 718 | } else { | 
|  | 719 | return "", fmt.Errorf("unknown location label %q", label) | 
|  | 720 | } | 
|  | 721 | } else if name == "genDir" { | 
|  | 722 | return android.PathForModuleGen(ctx).String(), nil | 
|  | 723 | } | 
|  | 724 | return "", fmt.Errorf("unknown variable '$(%s)'", name) | 
|  | 725 | }) | 
|  | 726 |  | 
|  | 727 | if err != nil { | 
|  | 728 | ctx.PropertyErrorf("args", "%s", err.Error()) | 
|  | 729 | } | 
|  | 730 |  | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 731 | return deps | 
|  | 732 | } | 
|  | 733 |  | 
|  | 734 | func (j *Javadoc) DepsMutator(ctx android.BottomUpMutatorContext) { | 
|  | 735 | j.addDeps(ctx) | 
|  | 736 | } | 
|  | 737 |  | 
|  | 738 | func (j *Javadoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
|  | 739 | deps := j.collectDeps(ctx) | 
|  | 740 |  | 
|  | 741 | var implicits android.Paths | 
|  | 742 | implicits = append(implicits, deps.bootClasspath...) | 
|  | 743 | implicits = append(implicits, deps.classpath...) | 
|  | 744 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 745 | var bootClasspathArgs, classpathArgs, sourcepathArgs string | 
| Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 746 |  | 
| Colin Cross | 83bb316 | 2018-06-25 15:48:06 -0700 | [diff] [blame] | 747 | javaVersion := getJavaVersion(ctx, String(j.properties.Java_version), sdkContext(j)) | 
| Colin Cross | 997262f | 2018-06-19 22:49:39 -0700 | [diff] [blame] | 748 | if len(deps.bootClasspath) > 0 { | 
|  | 749 | var systemModules classpath | 
|  | 750 | if deps.systemModules != nil { | 
|  | 751 | systemModules = append(systemModules, deps.systemModules) | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 752 | } | 
| Colin Cross | 997262f | 2018-06-19 22:49:39 -0700 | [diff] [blame] | 753 | bootClasspathArgs = systemModules.FormJavaSystemModulesPath("--system ", ctx.Device()) | 
|  | 754 | bootClasspathArgs = bootClasspathArgs + " --patch-module java.base=." | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 755 | } | 
|  | 756 | if len(deps.classpath.Strings()) > 0 { | 
|  | 757 | classpathArgs = "-classpath " + strings.Join(deps.classpath.Strings(), ":") | 
|  | 758 | } | 
|  | 759 |  | 
|  | 760 | implicits = append(implicits, j.srcJars...) | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 761 | implicits = append(implicits, j.argFiles...) | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 762 |  | 
| Nan Zhang | af322cc | 2018-06-19 15:15:38 -0700 | [diff] [blame] | 763 | opts := "-source " + javaVersion + " -J-Xmx1024m -XDignore.symbol.file -Xdoclint:none" | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 764 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 765 | sourcepathArgs = "-sourcepath " + strings.Join(j.sourcepaths.Strings(), ":") | 
|  | 766 |  | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 767 | ctx.Build(pctx, android.BuildParams{ | 
|  | 768 | Rule:           javadoc, | 
|  | 769 | Description:    "Javadoc", | 
| Nan Zhang | ccff0f7 | 2018-03-08 17:26:16 -0800 | [diff] [blame] | 770 | Output:         j.stubsSrcJar, | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 771 | ImplicitOutput: j.docZip, | 
|  | 772 | Inputs:         j.srcFiles, | 
|  | 773 | Implicits:      implicits, | 
|  | 774 | Args: map[string]string{ | 
| Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 775 | "outDir":            android.PathForModuleOut(ctx, "out").String(), | 
|  | 776 | "srcJarDir":         android.PathForModuleOut(ctx, "srcjars").String(), | 
|  | 777 | "stubsDir":          android.PathForModuleOut(ctx, "stubsDir").String(), | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 778 | "srcJars":           strings.Join(j.srcJars.Strings(), " "), | 
|  | 779 | "opts":              opts, | 
| Nan Zhang | 853f420 | 2018-04-12 16:55:56 -0700 | [diff] [blame] | 780 | "bootclasspathArgs": bootClasspathArgs, | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 781 | "classpathArgs":     classpathArgs, | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 782 | "sourcepathArgs":    sourcepathArgs, | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 783 | "docZip":            j.docZip.String(), | 
|  | 784 | }, | 
|  | 785 | }) | 
|  | 786 | } | 
|  | 787 |  | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 788 | // | 
|  | 789 | // Droiddoc | 
|  | 790 | // | 
|  | 791 | type Droiddoc struct { | 
|  | 792 | Javadoc | 
|  | 793 |  | 
|  | 794 | properties        DroiddocProperties | 
|  | 795 | apiFile           android.WritablePath | 
|  | 796 | dexApiFile        android.WritablePath | 
|  | 797 | privateApiFile    android.WritablePath | 
|  | 798 | privateDexApiFile android.WritablePath | 
|  | 799 | removedApiFile    android.WritablePath | 
|  | 800 | removedDexApiFile android.WritablePath | 
|  | 801 | exactApiFile      android.WritablePath | 
|  | 802 | apiMappingFile    android.WritablePath | 
| Nan Zhang | 66dc236 | 2018-08-14 20:41:04 -0700 | [diff] [blame] | 803 | proguardFile      android.WritablePath | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 804 |  | 
|  | 805 | checkCurrentApiTimestamp      android.WritablePath | 
|  | 806 | updateCurrentApiTimestamp     android.WritablePath | 
|  | 807 | checkLastReleasedApiTimestamp android.WritablePath | 
|  | 808 |  | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 809 | apiFilePath android.Path | 
|  | 810 | } | 
|  | 811 |  | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 812 | func DroiddocFactory() android.Module { | 
|  | 813 | module := &Droiddoc{} | 
|  | 814 |  | 
|  | 815 | module.AddProperties(&module.properties, | 
|  | 816 | &module.Javadoc.properties) | 
|  | 817 |  | 
|  | 818 | InitDroiddocModule(module, android.HostAndDeviceSupported) | 
|  | 819 | return module | 
|  | 820 | } | 
|  | 821 |  | 
|  | 822 | func DroiddocHostFactory() android.Module { | 
|  | 823 | module := &Droiddoc{} | 
|  | 824 |  | 
|  | 825 | module.AddProperties(&module.properties, | 
|  | 826 | &module.Javadoc.properties) | 
|  | 827 |  | 
|  | 828 | InitDroiddocModule(module, android.HostSupported) | 
|  | 829 | return module | 
|  | 830 | } | 
|  | 831 |  | 
|  | 832 | func (d *Droiddoc) ApiFilePath() android.Path { | 
|  | 833 | return d.apiFilePath | 
|  | 834 | } | 
|  | 835 |  | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 836 | func (d *Droiddoc) DepsMutator(ctx android.BottomUpMutatorContext) { | 
|  | 837 | d.Javadoc.addDeps(ctx) | 
|  | 838 |  | 
| Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 839 | if String(d.properties.Custom_template) != "" { | 
| Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 840 | ctx.AddDependency(ctx.Module(), droiddocTemplateTag, String(d.properties.Custom_template)) | 
|  | 841 | } | 
|  | 842 |  | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 843 | // knowntags may contain filegroup or genrule. | 
|  | 844 | android.ExtractSourcesDeps(ctx, d.properties.Knowntags) | 
| Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 845 |  | 
| Nan Zhang | e2ba5d4 | 2018-07-11 15:16:55 -0700 | [diff] [blame] | 846 | if String(d.properties.Static_doc_index_redirect) != "" { | 
|  | 847 | android.ExtractSourceDeps(ctx, d.properties.Static_doc_index_redirect) | 
|  | 848 | } | 
|  | 849 |  | 
|  | 850 | if String(d.properties.Static_doc_properties) != "" { | 
|  | 851 | android.ExtractSourceDeps(ctx, d.properties.Static_doc_properties) | 
|  | 852 | } | 
|  | 853 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 854 | if apiCheckEnabled(d.properties.Check_api.Current, "current") { | 
| Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 855 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file) | 
|  | 856 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file) | 
|  | 857 | } | 
|  | 858 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 859 | if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") { | 
| Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 860 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file) | 
|  | 861 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file) | 
|  | 862 | } | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 863 | } | 
|  | 864 |  | 
| Nan Zhang | 66dc236 | 2018-08-14 20:41:04 -0700 | [diff] [blame] | 865 | func (d *Droiddoc) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths, | 
|  | 866 | deps deps) (droiddocBuilderFlags, error) { | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 867 | var flags droiddocBuilderFlags | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 868 |  | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 869 | *implicits = append(*implicits, deps.bootClasspath...) | 
|  | 870 | *implicits = append(*implicits, deps.classpath...) | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 871 |  | 
| Nan Zhang | c94f9d8 | 2018-06-26 10:02:26 -0700 | [diff] [blame] | 872 | if len(deps.bootClasspath.Strings()) > 0 { | 
|  | 873 | // 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] | 874 | flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath") | 
| Nan Zhang | 357466b | 2018-04-17 17:38:36 -0700 | [diff] [blame] | 875 | } | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 876 | flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath") | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 877 | // 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] | 878 | dokkaClasspath := classpath{} | 
|  | 879 | dokkaClasspath = append(dokkaClasspath, deps.bootClasspath...) | 
|  | 880 | dokkaClasspath = append(dokkaClasspath, deps.classpath...) | 
|  | 881 | flags.dokkaClasspathArgs = dokkaClasspath.FormJavaClassPath("-classpath") | 
| Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 882 |  | 
| Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 883 | // TODO(nanzhang): Remove this if- statement once we finish migration for all Doclava | 
|  | 884 | // based stubs generation. | 
|  | 885 | // In the future, all the docs generation depends on Metalava stubs (droidstubs) srcjar | 
|  | 886 | // dir. We need add the srcjar dir to -sourcepath arg, so that Javadoc can figure out | 
|  | 887 | // the correct package name base path. | 
|  | 888 | if len(d.Javadoc.properties.Local_sourcepaths) > 0 { | 
|  | 889 | flags.sourcepathArgs = "-sourcepath " + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") | 
|  | 890 | } else { | 
|  | 891 | flags.sourcepathArgs = "-sourcepath " + android.PathForModuleOut(ctx, "srcjars").String() | 
|  | 892 | } | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 893 |  | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 894 | return flags, nil | 
|  | 895 | } | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 896 |  | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 897 | func (d *Droiddoc) collectDoclavaDocsFlags(ctx android.ModuleContext, implicits *android.Paths, | 
| Nan Zhang | 443fa52 | 2018-08-20 20:58:28 -0700 | [diff] [blame] | 898 | jsilver, doclava android.Path) string { | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 899 |  | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 900 | *implicits = append(*implicits, jsilver) | 
|  | 901 | *implicits = append(*implicits, doclava) | 
| Nan Zhang | 3096374 | 2018-04-23 09:59:14 -0700 | [diff] [blame] | 902 |  | 
| Nan Zhang | 4613097 | 2018-06-04 11:28:01 -0700 | [diff] [blame] | 903 | var date string | 
|  | 904 | if runtime.GOOS == "darwin" { | 
|  | 905 | date = `date -r` | 
|  | 906 | } else { | 
|  | 907 | date = `date -d` | 
|  | 908 | } | 
|  | 909 |  | 
| Nan Zhang | 443fa52 | 2018-08-20 20:58:28 -0700 | [diff] [blame] | 910 | // Droiddoc always gets "-source 1.8" because it doesn't support 1.9 sources.  For modules with 1.9 | 
|  | 911 | // sources, droiddoc will get sources produced by metalava which will have already stripped out the | 
|  | 912 | // 1.9 language features. | 
|  | 913 | args := " -source 1.8 -J-Xmx1600m -J-XX:-OmitStackTraceInFastThrow -XDignore.symbol.file " + | 
| Nan Zhang | 3096374 | 2018-04-23 09:59:14 -0700 | [diff] [blame] | 914 | "-doclet com.google.doclava.Doclava -docletpath " + jsilver.String() + ":" + doclava.String() + " " + | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 915 | "-hdf page.build " + ctx.Config().BuildId() + "-" + ctx.Config().BuildNumberFromFile() + " " + | 
| Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 916 | `-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] | 917 |  | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 918 | if String(d.properties.Custom_template) == "" { | 
|  | 919 | // TODO: This is almost always droiddoc-templates-sdk | 
|  | 920 | ctx.PropertyErrorf("custom_template", "must specify a template") | 
|  | 921 | } | 
|  | 922 |  | 
|  | 923 | ctx.VisitDirectDepsWithTag(droiddocTemplateTag, func(m android.Module) { | 
| Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 924 | if t, ok := m.(*ExportedDroiddocDir); ok { | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 925 | *implicits = append(*implicits, t.deps...) | 
|  | 926 | args = args + " -templatedir " + t.dir.String() | 
|  | 927 | } else { | 
|  | 928 | ctx.PropertyErrorf("custom_template", "module %q is not a droiddoc_template", ctx.OtherModuleName(m)) | 
|  | 929 | } | 
|  | 930 | }) | 
|  | 931 |  | 
|  | 932 | if len(d.properties.Html_dirs) > 0 { | 
|  | 933 | htmlDir := android.PathForModuleSrc(ctx, d.properties.Html_dirs[0]) | 
|  | 934 | *implicits = append(*implicits, ctx.Glob(htmlDir.Join(ctx, "**/*").String(), nil)...) | 
|  | 935 | args = args + " -htmldir " + htmlDir.String() | 
|  | 936 | } | 
|  | 937 |  | 
|  | 938 | if len(d.properties.Html_dirs) > 1 { | 
|  | 939 | htmlDir2 := android.PathForModuleSrc(ctx, d.properties.Html_dirs[1]) | 
|  | 940 | *implicits = append(*implicits, ctx.Glob(htmlDir2.Join(ctx, "**/*").String(), nil)...) | 
|  | 941 | args = args + " -htmldir2 " + htmlDir2.String() | 
|  | 942 | } | 
|  | 943 |  | 
|  | 944 | if len(d.properties.Html_dirs) > 2 { | 
|  | 945 | ctx.PropertyErrorf("html_dirs", "Droiddoc only supports up to 2 html dirs") | 
|  | 946 | } | 
|  | 947 |  | 
|  | 948 | knownTags := ctx.ExpandSources(d.properties.Knowntags, nil) | 
|  | 949 | *implicits = append(*implicits, knownTags...) | 
|  | 950 |  | 
|  | 951 | for _, kt := range knownTags { | 
|  | 952 | args = args + " -knowntags " + kt.String() | 
|  | 953 | } | 
|  | 954 |  | 
|  | 955 | for _, hdf := range d.properties.Hdf { | 
|  | 956 | args = args + " -hdf " + hdf | 
|  | 957 | } | 
|  | 958 |  | 
|  | 959 | if String(d.properties.Proofread_file) != "" { | 
|  | 960 | proofreadFile := android.PathForModuleOut(ctx, String(d.properties.Proofread_file)) | 
|  | 961 | args = args + " -proofread " + proofreadFile.String() | 
|  | 962 | } | 
|  | 963 |  | 
|  | 964 | if String(d.properties.Todo_file) != "" { | 
|  | 965 | // tricky part: | 
|  | 966 | // we should not compute full path for todo_file through PathForModuleOut(). | 
|  | 967 | // the non-standard doclet will get the full path relative to "-o". | 
|  | 968 | args = args + " -todo " + String(d.properties.Todo_file) | 
|  | 969 | } | 
|  | 970 |  | 
|  | 971 | if String(d.properties.Resourcesdir) != "" { | 
|  | 972 | // TODO: should we add files under resourcesDir to the implicits? It seems that | 
|  | 973 | // resourcesDir is one sub dir of htmlDir | 
|  | 974 | resourcesDir := android.PathForModuleSrc(ctx, String(d.properties.Resourcesdir)) | 
|  | 975 | args = args + " -resourcesdir " + resourcesDir.String() | 
|  | 976 | } | 
|  | 977 |  | 
|  | 978 | if String(d.properties.Resourcesoutdir) != "" { | 
|  | 979 | // TODO: it seems -resourceoutdir reference/android/images/ didn't get generated anywhere. | 
|  | 980 | args = args + " -resourcesoutdir " + String(d.properties.Resourcesoutdir) | 
|  | 981 | } | 
|  | 982 | return args | 
|  | 983 | } | 
|  | 984 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 985 | func (d *Droiddoc) collectStubsFlags(ctx android.ModuleContext, | 
|  | 986 | implicitOutputs *android.WritablePaths) string { | 
|  | 987 | var doclavaFlags string | 
|  | 988 | if apiCheckEnabled(d.properties.Check_api.Current, "current") || | 
|  | 989 | apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") || | 
|  | 990 | String(d.properties.Api_filename) != "" { | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 991 | d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt") | 
|  | 992 | doclavaFlags += " -api " + d.apiFile.String() | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 993 | *implicitOutputs = append(*implicitOutputs, d.apiFile) | 
|  | 994 | d.apiFilePath = d.apiFile | 
|  | 995 | } | 
|  | 996 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 997 | if apiCheckEnabled(d.properties.Check_api.Current, "current") || | 
|  | 998 | apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") || | 
|  | 999 | String(d.properties.Removed_api_filename) != "" { | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1000 | d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt") | 
|  | 1001 | doclavaFlags += " -removedApi " + d.removedApiFile.String() | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1002 | *implicitOutputs = append(*implicitOutputs, d.removedApiFile) | 
|  | 1003 | } | 
|  | 1004 |  | 
|  | 1005 | if String(d.properties.Private_api_filename) != "" { | 
|  | 1006 | d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename)) | 
|  | 1007 | doclavaFlags += " -privateApi " + d.privateApiFile.String() | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1008 | *implicitOutputs = append(*implicitOutputs, d.privateApiFile) | 
|  | 1009 | } | 
|  | 1010 |  | 
|  | 1011 | if String(d.properties.Dex_api_filename) != "" { | 
|  | 1012 | d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename)) | 
|  | 1013 | doclavaFlags += " -dexApi " + d.dexApiFile.String() | 
|  | 1014 | *implicitOutputs = append(*implicitOutputs, d.dexApiFile) | 
|  | 1015 | } | 
|  | 1016 |  | 
|  | 1017 | if String(d.properties.Private_dex_api_filename) != "" { | 
|  | 1018 | d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename)) | 
|  | 1019 | doclavaFlags += " -privateDexApi " + d.privateDexApiFile.String() | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1020 | *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile) | 
|  | 1021 | } | 
|  | 1022 |  | 
|  | 1023 | if String(d.properties.Removed_dex_api_filename) != "" { | 
|  | 1024 | d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename)) | 
|  | 1025 | doclavaFlags += " -removedDexApi " + d.removedDexApiFile.String() | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1026 | *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile) | 
|  | 1027 | } | 
|  | 1028 |  | 
|  | 1029 | if String(d.properties.Exact_api_filename) != "" { | 
|  | 1030 | d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename)) | 
|  | 1031 | doclavaFlags += " -exactApi " + d.exactApiFile.String() | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1032 | *implicitOutputs = append(*implicitOutputs, d.exactApiFile) | 
|  | 1033 | } | 
|  | 1034 |  | 
|  | 1035 | if String(d.properties.Dex_mapping_filename) != "" { | 
|  | 1036 | d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename)) | 
|  | 1037 | doclavaFlags += " -apiMapping " + d.apiMappingFile.String() | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1038 | *implicitOutputs = append(*implicitOutputs, d.apiMappingFile) | 
|  | 1039 | } | 
|  | 1040 |  | 
| Nan Zhang | 66dc236 | 2018-08-14 20:41:04 -0700 | [diff] [blame] | 1041 | if String(d.properties.Proguard_filename) != "" { | 
|  | 1042 | d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename)) | 
|  | 1043 | doclavaFlags += " -proguard " + d.proguardFile.String() | 
| Nan Zhang | 66dc236 | 2018-08-14 20:41:04 -0700 | [diff] [blame] | 1044 | *implicitOutputs = append(*implicitOutputs, d.proguardFile) | 
|  | 1045 | } | 
|  | 1046 |  | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1047 | if BoolDefault(d.properties.Create_stubs, true) { | 
| Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 1048 | doclavaFlags += " -stubs " + android.PathForModuleOut(ctx, "stubsDir").String() | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1049 | } | 
|  | 1050 |  | 
|  | 1051 | if Bool(d.properties.Write_sdk_values) { | 
| Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 1052 | doclavaFlags += " -sdkvalues " + android.PathForModuleOut(ctx, "out").String() | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1053 | } | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1054 |  | 
|  | 1055 | return doclavaFlags | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1056 | } | 
|  | 1057 |  | 
|  | 1058 | func (d *Droiddoc) getPostDoclavaCmds(ctx android.ModuleContext, implicits *android.Paths) string { | 
|  | 1059 | var cmds string | 
|  | 1060 | if String(d.properties.Static_doc_index_redirect) != "" { | 
|  | 1061 | static_doc_index_redirect := ctx.ExpandSource(String(d.properties.Static_doc_index_redirect), | 
|  | 1062 | "static_doc_index_redirect") | 
|  | 1063 | *implicits = append(*implicits, static_doc_index_redirect) | 
|  | 1064 | cmds = cmds + " && cp " + static_doc_index_redirect.String() + " " + | 
| Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 1065 | android.PathForModuleOut(ctx, "out", "index.html").String() | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1066 | } | 
|  | 1067 |  | 
|  | 1068 | if String(d.properties.Static_doc_properties) != "" { | 
|  | 1069 | static_doc_properties := ctx.ExpandSource(String(d.properties.Static_doc_properties), | 
|  | 1070 | "static_doc_properties") | 
|  | 1071 | *implicits = append(*implicits, static_doc_properties) | 
|  | 1072 | cmds = cmds + " && cp " + static_doc_properties.String() + " " + | 
| Nan Zhang | de860a4 | 2018-08-08 16:32:21 -0700 | [diff] [blame] | 1073 | android.PathForModuleOut(ctx, "out", "source.properties").String() | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1074 | } | 
|  | 1075 | return cmds | 
|  | 1076 | } | 
|  | 1077 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1078 | func (d *Droiddoc) transformDoclava(ctx android.ModuleContext, implicits android.Paths, | 
|  | 1079 | implicitOutputs android.WritablePaths, | 
|  | 1080 | bootclasspathArgs, classpathArgs, sourcepathArgs, opts, postDoclavaCmds string) { | 
|  | 1081 | ctx.Build(pctx, android.BuildParams{ | 
|  | 1082 | Rule:            javadoc, | 
|  | 1083 | Description:     "Doclava", | 
|  | 1084 | Output:          d.Javadoc.stubsSrcJar, | 
|  | 1085 | Inputs:          d.Javadoc.srcFiles, | 
|  | 1086 | Implicits:       implicits, | 
|  | 1087 | ImplicitOutputs: implicitOutputs, | 
|  | 1088 | Args: map[string]string{ | 
|  | 1089 | "outDir":            android.PathForModuleOut(ctx, "out").String(), | 
|  | 1090 | "srcJarDir":         android.PathForModuleOut(ctx, "srcjars").String(), | 
|  | 1091 | "stubsDir":          android.PathForModuleOut(ctx, "stubsDir").String(), | 
|  | 1092 | "srcJars":           strings.Join(d.Javadoc.srcJars.Strings(), " "), | 
|  | 1093 | "opts":              opts, | 
|  | 1094 | "bootclasspathArgs": bootclasspathArgs, | 
|  | 1095 | "classpathArgs":     classpathArgs, | 
|  | 1096 | "sourcepathArgs":    sourcepathArgs, | 
|  | 1097 | "docZip":            d.Javadoc.docZip.String(), | 
|  | 1098 | "postDoclavaCmds":   postDoclavaCmds, | 
|  | 1099 | }, | 
|  | 1100 | }) | 
|  | 1101 | } | 
|  | 1102 |  | 
|  | 1103 | func (d *Droiddoc) transformCheckApi(ctx android.ModuleContext, apiFile, removedApiFile android.Path, | 
|  | 1104 | checkApiClasspath classpath, msg, opts string, output android.WritablePath) { | 
|  | 1105 | ctx.Build(pctx, android.BuildParams{ | 
|  | 1106 | Rule:        apiCheck, | 
|  | 1107 | Description: "Doclava Check API", | 
|  | 1108 | Output:      output, | 
|  | 1109 | Inputs:      nil, | 
|  | 1110 | Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile}, | 
|  | 1111 | checkApiClasspath...), | 
|  | 1112 | Args: map[string]string{ | 
|  | 1113 | "msg":                   msg, | 
|  | 1114 | "classpath":             checkApiClasspath.FormJavaClassPath(""), | 
|  | 1115 | "opts":                  opts, | 
|  | 1116 | "apiFile":               apiFile.String(), | 
|  | 1117 | "apiFileToCheck":        d.apiFile.String(), | 
|  | 1118 | "removedApiFile":        removedApiFile.String(), | 
|  | 1119 | "removedApiFileToCheck": d.removedApiFile.String(), | 
|  | 1120 | }, | 
|  | 1121 | }) | 
|  | 1122 | } | 
|  | 1123 |  | 
|  | 1124 | func (d *Droiddoc) transformDokka(ctx android.ModuleContext, implicits android.Paths, | 
|  | 1125 | classpathArgs, opts string) { | 
|  | 1126 | ctx.Build(pctx, android.BuildParams{ | 
|  | 1127 | Rule:        dokka, | 
|  | 1128 | Description: "Dokka", | 
|  | 1129 | Output:      d.Javadoc.stubsSrcJar, | 
|  | 1130 | Inputs:      d.Javadoc.srcFiles, | 
|  | 1131 | Implicits:   implicits, | 
|  | 1132 | Args: map[string]string{ | 
| Nan Zhang | 3ffc352 | 2018-11-29 10:42:47 -0800 | [diff] [blame] | 1133 | "outDir":        android.PathForModuleOut(ctx, "dokka-out").String(), | 
|  | 1134 | "srcJarDir":     android.PathForModuleOut(ctx, "dokka-srcjars").String(), | 
|  | 1135 | "stubsDir":      android.PathForModuleOut(ctx, "dokka-stubsDir").String(), | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1136 | "srcJars":       strings.Join(d.Javadoc.srcJars.Strings(), " "), | 
|  | 1137 | "classpathArgs": classpathArgs, | 
|  | 1138 | "opts":          opts, | 
|  | 1139 | "docZip":        d.Javadoc.docZip.String(), | 
|  | 1140 | }, | 
|  | 1141 | }) | 
|  | 1142 | } | 
|  | 1143 |  | 
|  | 1144 | func (d *Droiddoc) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
|  | 1145 | deps := d.Javadoc.collectDeps(ctx) | 
|  | 1146 |  | 
|  | 1147 | jsilver := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jsilver.jar") | 
|  | 1148 | doclava := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "doclava.jar") | 
|  | 1149 | java8Home := ctx.Config().Getenv("ANDROID_JAVA8_HOME") | 
|  | 1150 | checkApiClasspath := classpath{jsilver, doclava, android.PathForSource(ctx, java8Home, "lib/tools.jar")} | 
|  | 1151 |  | 
|  | 1152 | var implicits android.Paths | 
|  | 1153 | implicits = append(implicits, d.Javadoc.srcJars...) | 
|  | 1154 | implicits = append(implicits, d.Javadoc.argFiles...) | 
|  | 1155 |  | 
|  | 1156 | var implicitOutputs android.WritablePaths | 
|  | 1157 | implicitOutputs = append(implicitOutputs, d.Javadoc.docZip) | 
|  | 1158 | for _, o := range d.Javadoc.properties.Out { | 
|  | 1159 | implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o)) | 
|  | 1160 | } | 
|  | 1161 |  | 
|  | 1162 | flags, err := d.initBuilderFlags(ctx, &implicits, deps) | 
|  | 1163 | if err != nil { | 
|  | 1164 | return | 
|  | 1165 | } | 
|  | 1166 |  | 
|  | 1167 | flags.doclavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs) | 
|  | 1168 | if Bool(d.properties.Dokka_enabled) { | 
|  | 1169 | d.transformDokka(ctx, implicits, flags.classpathArgs, d.Javadoc.args) | 
|  | 1170 | } else { | 
|  | 1171 | flags.doclavaDocsFlags = d.collectDoclavaDocsFlags(ctx, &implicits, jsilver, doclava) | 
|  | 1172 | flags.postDoclavaCmds = d.getPostDoclavaCmds(ctx, &implicits) | 
|  | 1173 | d.transformDoclava(ctx, implicits, implicitOutputs, flags.bootClasspathArgs, flags.classpathArgs, | 
|  | 1174 | flags.sourcepathArgs, flags.doclavaDocsFlags+flags.doclavaStubsFlags+" "+d.Javadoc.args, | 
|  | 1175 | flags.postDoclavaCmds) | 
|  | 1176 | } | 
|  | 1177 |  | 
|  | 1178 | if apiCheckEnabled(d.properties.Check_api.Current, "current") && | 
|  | 1179 | !ctx.Config().IsPdkBuild() { | 
|  | 1180 | apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file), | 
|  | 1181 | "check_api.current.api_file") | 
|  | 1182 | removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file), | 
|  | 1183 | "check_api.current_removed_api_file") | 
|  | 1184 |  | 
|  | 1185 | d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp") | 
|  | 1186 | d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath, | 
|  | 1187 | fmt.Sprintf(`\n******************************\n`+ | 
|  | 1188 | `You have tried to change the API from what has been previously approved.\n\n`+ | 
|  | 1189 | `To make these errors go away, you have two choices:\n`+ | 
|  | 1190 | `   1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+ | 
|  | 1191 | `      errors above.\n\n`+ | 
|  | 1192 | `   2. You can update current.txt by executing the following command:\n`+ | 
|  | 1193 | `         make %s-update-current-api\n\n`+ | 
|  | 1194 | `      To submit the revised current.txt to the main Android repository,\n`+ | 
|  | 1195 | `      you will need approval.\n`+ | 
|  | 1196 | `******************************\n`, ctx.ModuleName()), String(d.properties.Check_api.Current.Args), | 
|  | 1197 | d.checkCurrentApiTimestamp) | 
|  | 1198 |  | 
|  | 1199 | d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp") | 
|  | 1200 | transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile, | 
|  | 1201 | d.updateCurrentApiTimestamp) | 
|  | 1202 | } | 
|  | 1203 |  | 
|  | 1204 | if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") && | 
|  | 1205 | !ctx.Config().IsPdkBuild() { | 
|  | 1206 | apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file), | 
|  | 1207 | "check_api.last_released.api_file") | 
|  | 1208 | removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file), | 
|  | 1209 | "check_api.last_released.removed_api_file") | 
|  | 1210 |  | 
|  | 1211 | d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp") | 
|  | 1212 | d.transformCheckApi(ctx, apiFile, removedApiFile, checkApiClasspath, | 
|  | 1213 | `\n******************************\n`+ | 
|  | 1214 | `You have tried to change the API from what has been previously released in\n`+ | 
|  | 1215 | `an SDK.  Please fix the errors listed above.\n`+ | 
|  | 1216 | `******************************\n`, String(d.properties.Check_api.Last_released.Args), | 
|  | 1217 | d.checkLastReleasedApiTimestamp) | 
|  | 1218 | } | 
|  | 1219 | } | 
|  | 1220 |  | 
|  | 1221 | // | 
|  | 1222 | // Droidstubs | 
|  | 1223 | // | 
|  | 1224 | type Droidstubs struct { | 
|  | 1225 | Javadoc | 
|  | 1226 |  | 
| Pete Gillin | 581d608 | 2018-10-22 15:55:04 +0100 | [diff] [blame] | 1227 | properties              DroidstubsProperties | 
|  | 1228 | apiFile                 android.WritablePath | 
|  | 1229 | apiXmlFile              android.WritablePath | 
|  | 1230 | lastReleasedApiXmlFile  android.WritablePath | 
|  | 1231 | dexApiFile              android.WritablePath | 
|  | 1232 | privateApiFile          android.WritablePath | 
|  | 1233 | privateDexApiFile       android.WritablePath | 
|  | 1234 | removedApiFile          android.WritablePath | 
|  | 1235 | removedDexApiFile       android.WritablePath | 
|  | 1236 | apiMappingFile          android.WritablePath | 
|  | 1237 | exactApiFile            android.WritablePath | 
|  | 1238 | proguardFile            android.WritablePath | 
|  | 1239 | nullabilityWarningsFile android.WritablePath | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1240 |  | 
|  | 1241 | checkCurrentApiTimestamp      android.WritablePath | 
|  | 1242 | updateCurrentApiTimestamp     android.WritablePath | 
|  | 1243 | checkLastReleasedApiTimestamp android.WritablePath | 
|  | 1244 |  | 
| Pete Gillin | 581d608 | 2018-10-22 15:55:04 +0100 | [diff] [blame] | 1245 | checkNullabilityWarningsTimestamp android.WritablePath | 
|  | 1246 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1247 | annotationsZip android.WritablePath | 
| Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1248 | apiVersionsXml android.WritablePath | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1249 |  | 
|  | 1250 | apiFilePath android.Path | 
| Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1251 |  | 
|  | 1252 | jdiffDocZip      android.WritablePath | 
|  | 1253 | jdiffStubsSrcJar android.WritablePath | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1254 | } | 
|  | 1255 |  | 
|  | 1256 | func DroidstubsFactory() android.Module { | 
|  | 1257 | module := &Droidstubs{} | 
|  | 1258 |  | 
|  | 1259 | module.AddProperties(&module.properties, | 
|  | 1260 | &module.Javadoc.properties) | 
|  | 1261 |  | 
|  | 1262 | InitDroiddocModule(module, android.HostAndDeviceSupported) | 
|  | 1263 | return module | 
|  | 1264 | } | 
|  | 1265 |  | 
|  | 1266 | func DroidstubsHostFactory() android.Module { | 
|  | 1267 | module := &Droidstubs{} | 
|  | 1268 |  | 
|  | 1269 | module.AddProperties(&module.properties, | 
|  | 1270 | &module.Javadoc.properties) | 
|  | 1271 |  | 
|  | 1272 | InitDroiddocModule(module, android.HostSupported) | 
|  | 1273 | return module | 
|  | 1274 | } | 
|  | 1275 |  | 
|  | 1276 | func (d *Droidstubs) ApiFilePath() android.Path { | 
|  | 1277 | return d.apiFilePath | 
|  | 1278 | } | 
|  | 1279 |  | 
|  | 1280 | func (d *Droidstubs) DepsMutator(ctx android.BottomUpMutatorContext) { | 
|  | 1281 | d.Javadoc.addDeps(ctx) | 
|  | 1282 |  | 
|  | 1283 | if apiCheckEnabled(d.properties.Check_api.Current, "current") { | 
|  | 1284 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Api_file) | 
|  | 1285 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Current.Removed_api_file) | 
|  | 1286 | } | 
|  | 1287 |  | 
|  | 1288 | if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") { | 
|  | 1289 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Api_file) | 
|  | 1290 | android.ExtractSourceDeps(ctx, d.properties.Check_api.Last_released.Removed_api_file) | 
|  | 1291 | } | 
|  | 1292 |  | 
|  | 1293 | if String(d.properties.Previous_api) != "" { | 
|  | 1294 | android.ExtractSourceDeps(ctx, d.properties.Previous_api) | 
|  | 1295 | } | 
|  | 1296 |  | 
|  | 1297 | if len(d.properties.Merge_annotations_dirs) != 0 { | 
|  | 1298 | for _, mergeAnnotationsDir := range d.properties.Merge_annotations_dirs { | 
|  | 1299 | ctx.AddDependency(ctx.Module(), metalavaMergeAnnotationsDirTag, mergeAnnotationsDir) | 
|  | 1300 | } | 
|  | 1301 | } | 
| Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1302 |  | 
| Pete Gillin | 7716790 | 2018-09-19 18:16:26 +0100 | [diff] [blame] | 1303 | if len(d.properties.Merge_inclusion_annotations_dirs) != 0 { | 
|  | 1304 | for _, mergeInclusionAnnotationsDir := range d.properties.Merge_inclusion_annotations_dirs { | 
|  | 1305 | ctx.AddDependency(ctx.Module(), metalavaMergeInclusionAnnotationsDirTag, mergeInclusionAnnotationsDir) | 
|  | 1306 | } | 
|  | 1307 | } | 
|  | 1308 |  | 
| Pete Gillin | c382a56 | 2018-11-14 18:45:46 +0000 | [diff] [blame] | 1309 | if String(d.properties.Validate_nullability_from_list) != "" { | 
|  | 1310 | android.ExtractSourceDeps(ctx, d.properties.Validate_nullability_from_list) | 
|  | 1311 | } | 
| Pete Gillin | 581d608 | 2018-10-22 15:55:04 +0100 | [diff] [blame] | 1312 | if String(d.properties.Check_nullability_warnings) != "" { | 
|  | 1313 | android.ExtractSourceDeps(ctx, d.properties.Check_nullability_warnings) | 
|  | 1314 | } | 
|  | 1315 |  | 
| Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1316 | if len(d.properties.Api_levels_annotations_dirs) != 0 { | 
|  | 1317 | for _, apiLevelsAnnotationsDir := range d.properties.Api_levels_annotations_dirs { | 
|  | 1318 | ctx.AddDependency(ctx.Module(), metalavaAPILevelsAnnotationsDirTag, apiLevelsAnnotationsDir) | 
|  | 1319 | } | 
|  | 1320 | } | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1321 | } | 
|  | 1322 |  | 
|  | 1323 | func (d *Droidstubs) initBuilderFlags(ctx android.ModuleContext, implicits *android.Paths, | 
|  | 1324 | deps deps) (droiddocBuilderFlags, error) { | 
|  | 1325 | var flags droiddocBuilderFlags | 
|  | 1326 |  | 
|  | 1327 | *implicits = append(*implicits, deps.bootClasspath...) | 
|  | 1328 | *implicits = append(*implicits, deps.classpath...) | 
|  | 1329 |  | 
|  | 1330 | // continue to use -bootclasspath even if Metalava under -source 1.9 is enabled | 
|  | 1331 | // since it doesn't support system modules yet. | 
|  | 1332 | if len(deps.bootClasspath.Strings()) > 0 { | 
|  | 1333 | // For OpenJDK 8 we can use -bootclasspath to define the core libraries code. | 
|  | 1334 | flags.bootClasspathArgs = deps.bootClasspath.FormJavaClassPath("-bootclasspath") | 
|  | 1335 | } | 
|  | 1336 | flags.classpathArgs = deps.classpath.FormJavaClassPath("-classpath") | 
|  | 1337 |  | 
| Sundong Ahn | 56dce44 | 2018-10-05 18:41:09 +0900 | [diff] [blame] | 1338 | flags.sourcepathArgs = "-sourcepath \"" + strings.Join(d.Javadoc.sourcepaths.Strings(), ":") + "\"" | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1339 | return flags, nil | 
|  | 1340 | } | 
|  | 1341 |  | 
|  | 1342 | func (d *Droidstubs) collectStubsFlags(ctx android.ModuleContext, | 
|  | 1343 | implicitOutputs *android.WritablePaths) string { | 
|  | 1344 | var metalavaFlags string | 
|  | 1345 | if apiCheckEnabled(d.properties.Check_api.Current, "current") || | 
|  | 1346 | apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") || | 
|  | 1347 | String(d.properties.Api_filename) != "" { | 
|  | 1348 | d.apiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.txt") | 
|  | 1349 | metalavaFlags = metalavaFlags + " --api " + d.apiFile.String() | 
|  | 1350 | *implicitOutputs = append(*implicitOutputs, d.apiFile) | 
|  | 1351 | d.apiFilePath = d.apiFile | 
|  | 1352 | } | 
|  | 1353 |  | 
|  | 1354 | if apiCheckEnabled(d.properties.Check_api.Current, "current") || | 
|  | 1355 | apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") || | 
|  | 1356 | String(d.properties.Removed_api_filename) != "" { | 
|  | 1357 | d.removedApiFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_removed.txt") | 
|  | 1358 | metalavaFlags = metalavaFlags + " --removed-api " + d.removedApiFile.String() | 
|  | 1359 | *implicitOutputs = append(*implicitOutputs, d.removedApiFile) | 
|  | 1360 | } | 
|  | 1361 |  | 
|  | 1362 | if String(d.properties.Private_api_filename) != "" { | 
|  | 1363 | d.privateApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_api_filename)) | 
|  | 1364 | metalavaFlags = metalavaFlags + " --private-api " + d.privateApiFile.String() | 
|  | 1365 | *implicitOutputs = append(*implicitOutputs, d.privateApiFile) | 
|  | 1366 | } | 
|  | 1367 |  | 
|  | 1368 | if String(d.properties.Dex_api_filename) != "" { | 
|  | 1369 | d.dexApiFile = android.PathForModuleOut(ctx, String(d.properties.Dex_api_filename)) | 
|  | 1370 | metalavaFlags += " --dex-api " + d.dexApiFile.String() | 
|  | 1371 | *implicitOutputs = append(*implicitOutputs, d.dexApiFile) | 
|  | 1372 | } | 
|  | 1373 |  | 
|  | 1374 | if String(d.properties.Private_dex_api_filename) != "" { | 
|  | 1375 | d.privateDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Private_dex_api_filename)) | 
|  | 1376 | metalavaFlags = metalavaFlags + " --private-dex-api " + d.privateDexApiFile.String() | 
|  | 1377 | *implicitOutputs = append(*implicitOutputs, d.privateDexApiFile) | 
|  | 1378 | } | 
|  | 1379 |  | 
|  | 1380 | if String(d.properties.Removed_dex_api_filename) != "" { | 
|  | 1381 | d.removedDexApiFile = android.PathForModuleOut(ctx, String(d.properties.Removed_dex_api_filename)) | 
|  | 1382 | metalavaFlags = metalavaFlags + " --removed-dex-api " + d.removedDexApiFile.String() | 
|  | 1383 | *implicitOutputs = append(*implicitOutputs, d.removedDexApiFile) | 
|  | 1384 | } | 
|  | 1385 |  | 
|  | 1386 | if String(d.properties.Exact_api_filename) != "" { | 
|  | 1387 | d.exactApiFile = android.PathForModuleOut(ctx, String(d.properties.Exact_api_filename)) | 
|  | 1388 | metalavaFlags = metalavaFlags + " --exact-api " + d.exactApiFile.String() | 
|  | 1389 | *implicitOutputs = append(*implicitOutputs, d.exactApiFile) | 
|  | 1390 | } | 
|  | 1391 |  | 
| Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1392 | if String(d.properties.Dex_mapping_filename) != "" { | 
|  | 1393 | d.apiMappingFile = android.PathForModuleOut(ctx, String(d.properties.Dex_mapping_filename)) | 
|  | 1394 | metalavaFlags = metalavaFlags + " --dex-api-mapping " + d.apiMappingFile.String() | 
|  | 1395 | *implicitOutputs = append(*implicitOutputs, d.apiMappingFile) | 
|  | 1396 | } | 
|  | 1397 |  | 
| Nan Zhang | 199645c | 2018-09-19 12:40:06 -0700 | [diff] [blame] | 1398 | if String(d.properties.Proguard_filename) != "" { | 
|  | 1399 | d.proguardFile = android.PathForModuleOut(ctx, String(d.properties.Proguard_filename)) | 
|  | 1400 | metalavaFlags += " --proguard " + d.proguardFile.String() | 
|  | 1401 | *implicitOutputs = append(*implicitOutputs, d.proguardFile) | 
|  | 1402 | } | 
|  | 1403 |  | 
| Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1404 | if Bool(d.properties.Write_sdk_values) { | 
|  | 1405 | metalavaFlags = metalavaFlags + " --sdk-values " + android.PathForModuleOut(ctx, "out").String() | 
|  | 1406 | } | 
|  | 1407 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1408 | if Bool(d.properties.Create_doc_stubs) { | 
|  | 1409 | metalavaFlags += " --doc-stubs " + android.PathForModuleOut(ctx, "stubsDir").String() | 
|  | 1410 | } else { | 
|  | 1411 | metalavaFlags += " --stubs " + android.PathForModuleOut(ctx, "stubsDir").String() | 
|  | 1412 | } | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1413 | return metalavaFlags | 
|  | 1414 | } | 
|  | 1415 |  | 
|  | 1416 | func (d *Droidstubs) collectAnnotationsFlags(ctx android.ModuleContext, | 
| Nan Zhang | dee152b | 2018-12-26 16:06:37 -0800 | [diff] [blame] | 1417 | implicits *android.Paths, implicitOutputs *android.WritablePaths) (string, string) { | 
|  | 1418 | var flags, mergeAnnoDirFlags string | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1419 | if Bool(d.properties.Annotations_enabled) { | 
| Pete Gillin | a262c05 | 2018-09-14 14:25:48 +0100 | [diff] [blame] | 1420 | flags += " --include-annotations" | 
| Pete Gillin | c382a56 | 2018-11-14 18:45:46 +0000 | [diff] [blame] | 1421 | validatingNullability := | 
|  | 1422 | strings.Contains(d.Javadoc.args, "--validate-nullability-from-merged-stubs") || | 
|  | 1423 | String(d.properties.Validate_nullability_from_list) != "" | 
| Pete Gillin | a262c05 | 2018-09-14 14:25:48 +0100 | [diff] [blame] | 1424 | migratingNullability := String(d.properties.Previous_api) != "" | 
|  | 1425 | if !(migratingNullability || validatingNullability) { | 
|  | 1426 | ctx.PropertyErrorf("previous_api", | 
|  | 1427 | "has to be non-empty if annotations was enabled (unless validating nullability)") | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1428 | } | 
| Pete Gillin | a262c05 | 2018-09-14 14:25:48 +0100 | [diff] [blame] | 1429 | if migratingNullability { | 
|  | 1430 | previousApi := ctx.ExpandSource(String(d.properties.Previous_api), "previous_api") | 
|  | 1431 | *implicits = append(*implicits, previousApi) | 
|  | 1432 | flags += " --migrate-nullness " + previousApi.String() | 
|  | 1433 | } | 
| Pete Gillin | c382a56 | 2018-11-14 18:45:46 +0000 | [diff] [blame] | 1434 | if s := String(d.properties.Validate_nullability_from_list); s != "" { | 
|  | 1435 | flags += " --validate-nullability-from-list " + ctx.ExpandSource(s, "validate_nullability_from_list").String() | 
|  | 1436 | } | 
| Pete Gillin | a262c05 | 2018-09-14 14:25:48 +0100 | [diff] [blame] | 1437 | if validatingNullability { | 
| Pete Gillin | 581d608 | 2018-10-22 15:55:04 +0100 | [diff] [blame] | 1438 | d.nullabilityWarningsFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_nullability_warnings.txt") | 
|  | 1439 | *implicitOutputs = append(*implicitOutputs, d.nullabilityWarningsFile) | 
|  | 1440 | flags += " --nullability-warnings-txt " + d.nullabilityWarningsFile.String() | 
| Pete Gillin | a262c05 | 2018-09-14 14:25:48 +0100 | [diff] [blame] | 1441 | } | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1442 |  | 
|  | 1443 | d.annotationsZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"_annotations.zip") | 
|  | 1444 | *implicitOutputs = append(*implicitOutputs, d.annotationsZip) | 
|  | 1445 |  | 
| Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1446 | flags += " --extract-annotations " + d.annotationsZip.String() | 
|  | 1447 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1448 | if len(d.properties.Merge_annotations_dirs) == 0 { | 
| Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1449 | ctx.PropertyErrorf("merge_annotations_dirs", | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1450 | "has to be non-empty if annotations was enabled!") | 
|  | 1451 | } | 
| Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1452 | ctx.VisitDirectDepsWithTag(metalavaMergeAnnotationsDirTag, func(m android.Module) { | 
|  | 1453 | if t, ok := m.(*ExportedDroiddocDir); ok { | 
|  | 1454 | *implicits = append(*implicits, t.deps...) | 
| Nan Zhang | dee152b | 2018-12-26 16:06:37 -0800 | [diff] [blame] | 1455 | mergeAnnoDirFlags += " --merge-qualifier-annotations " + t.dir.String() | 
| Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1456 | } else { | 
| Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1457 | ctx.PropertyErrorf("merge_annotations_dirs", | 
| Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1458 | "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m)) | 
|  | 1459 | } | 
|  | 1460 | }) | 
| Nan Zhang | dee152b | 2018-12-26 16:06:37 -0800 | [diff] [blame] | 1461 | flags += mergeAnnoDirFlags | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1462 | // TODO(tnorbye): find owners to fix these warnings when annotation was enabled. | 
| Neil Fuller | b2f14ec | 2018-10-21 22:13:19 +0100 | [diff] [blame] | 1463 | flags += " --hide HiddenTypedefConstant --hide SuperfluousPrefix --hide AnnotationExtraction" | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1464 | } | 
| Neil Fuller | b2f14ec | 2018-10-21 22:13:19 +0100 | [diff] [blame] | 1465 |  | 
| Nan Zhang | dee152b | 2018-12-26 16:06:37 -0800 | [diff] [blame] | 1466 | return flags, mergeAnnoDirFlags | 
| Neil Fuller | b2f14ec | 2018-10-21 22:13:19 +0100 | [diff] [blame] | 1467 | } | 
|  | 1468 |  | 
|  | 1469 | func (d *Droidstubs) collectInclusionAnnotationsFlags(ctx android.ModuleContext, | 
|  | 1470 | implicits *android.Paths, implicitOutputs *android.WritablePaths) string { | 
|  | 1471 | var flags string | 
| Pete Gillin | 7716790 | 2018-09-19 18:16:26 +0100 | [diff] [blame] | 1472 | ctx.VisitDirectDepsWithTag(metalavaMergeInclusionAnnotationsDirTag, func(m android.Module) { | 
|  | 1473 | if t, ok := m.(*ExportedDroiddocDir); ok { | 
|  | 1474 | *implicits = append(*implicits, t.deps...) | 
|  | 1475 | flags += " --merge-inclusion-annotations " + t.dir.String() | 
|  | 1476 | } else { | 
|  | 1477 | ctx.PropertyErrorf("merge_inclusion_annotations_dirs", | 
|  | 1478 | "module %q is not a metalava merge-annotations dir", ctx.OtherModuleName(m)) | 
|  | 1479 | } | 
|  | 1480 | }) | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1481 |  | 
|  | 1482 | return flags | 
|  | 1483 | } | 
|  | 1484 |  | 
| Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1485 | func (d *Droidstubs) collectAPILevelsAnnotationsFlags(ctx android.ModuleContext, | 
|  | 1486 | implicits *android.Paths, implicitOutputs *android.WritablePaths) string { | 
|  | 1487 | var flags string | 
|  | 1488 | if Bool(d.properties.Api_levels_annotations_enabled) { | 
|  | 1489 | d.apiVersionsXml = android.PathForModuleOut(ctx, "api-versions.xml") | 
|  | 1490 | *implicitOutputs = append(*implicitOutputs, d.apiVersionsXml) | 
|  | 1491 |  | 
|  | 1492 | if len(d.properties.Api_levels_annotations_dirs) == 0 { | 
|  | 1493 | ctx.PropertyErrorf("api_levels_annotations_dirs", | 
|  | 1494 | "has to be non-empty if api levels annotations was enabled!") | 
|  | 1495 | } | 
|  | 1496 |  | 
|  | 1497 | flags = " --generate-api-levels " + d.apiVersionsXml.String() + " --apply-api-levels " + | 
|  | 1498 | d.apiVersionsXml.String() + " --current-version " + ctx.Config().PlatformSdkVersion() + | 
|  | 1499 | " --current-codename " + ctx.Config().PlatformSdkCodename() + " " | 
|  | 1500 |  | 
|  | 1501 | ctx.VisitDirectDepsWithTag(metalavaAPILevelsAnnotationsDirTag, func(m android.Module) { | 
|  | 1502 | if t, ok := m.(*ExportedDroiddocDir); ok { | 
|  | 1503 | var androidJars android.Paths | 
|  | 1504 | for _, dep := range t.deps { | 
|  | 1505 | if strings.HasSuffix(dep.String(), "android.jar") { | 
|  | 1506 | androidJars = append(androidJars, dep) | 
|  | 1507 | } | 
|  | 1508 | } | 
|  | 1509 | *implicits = append(*implicits, androidJars...) | 
|  | 1510 | flags += " --android-jar-pattern " + t.dir.String() + "/%/android.jar " | 
|  | 1511 | } else { | 
|  | 1512 | ctx.PropertyErrorf("api_levels_annotations_dirs", | 
|  | 1513 | "module %q is not a metalava api-levels-annotations dir", ctx.OtherModuleName(m)) | 
|  | 1514 | } | 
|  | 1515 | }) | 
|  | 1516 |  | 
|  | 1517 | } | 
|  | 1518 |  | 
|  | 1519 | return flags | 
|  | 1520 | } | 
|  | 1521 |  | 
| Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1522 | func (d *Droidstubs) collectApiToXmlFlags(ctx android.ModuleContext, implicits *android.Paths, | 
|  | 1523 | implicitOutputs *android.WritablePaths) string { | 
|  | 1524 | var flags string | 
|  | 1525 | if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() { | 
|  | 1526 | if d.apiFile.String() == "" { | 
|  | 1527 | ctx.ModuleErrorf("API signature file has to be specified in Metalava when jdiff is enabled.") | 
|  | 1528 | } | 
|  | 1529 |  | 
|  | 1530 | d.apiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_api.xml") | 
|  | 1531 | *implicitOutputs = append(*implicitOutputs, d.apiXmlFile) | 
|  | 1532 |  | 
|  | 1533 | flags = " --api-xml " + d.apiXmlFile.String() | 
|  | 1534 |  | 
|  | 1535 | if String(d.properties.Check_api.Last_released.Api_file) == "" { | 
|  | 1536 | ctx.PropertyErrorf("check_api.last_released.api_file", | 
|  | 1537 | "has to be non-empty if jdiff was enabled!") | 
|  | 1538 | } | 
|  | 1539 | lastReleasedApi := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file), | 
|  | 1540 | "check_api.last_released.api_file") | 
|  | 1541 | *implicits = append(*implicits, lastReleasedApi) | 
|  | 1542 |  | 
|  | 1543 | d.lastReleasedApiXmlFile = android.PathForModuleOut(ctx, ctx.ModuleName()+"_last_released_api.xml") | 
|  | 1544 | *implicitOutputs = append(*implicitOutputs, d.lastReleasedApiXmlFile) | 
|  | 1545 |  | 
|  | 1546 | flags += " --convert-to-jdiff " + lastReleasedApi.String() + " " + | 
|  | 1547 | d.lastReleasedApiXmlFile.String() | 
|  | 1548 | } | 
|  | 1549 |  | 
|  | 1550 | return flags | 
|  | 1551 | } | 
|  | 1552 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1553 | func (d *Droidstubs) transformMetalava(ctx android.ModuleContext, implicits android.Paths, | 
|  | 1554 | implicitOutputs android.WritablePaths, javaVersion, | 
|  | 1555 | bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) { | 
| Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1556 |  | 
| Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1557 | ctx.Build(pctx, android.BuildParams{ | 
|  | 1558 | Rule:            metalava, | 
|  | 1559 | Description:     "Metalava", | 
|  | 1560 | Output:          d.Javadoc.stubsSrcJar, | 
|  | 1561 | Inputs:          d.Javadoc.srcFiles, | 
|  | 1562 | Implicits:       implicits, | 
|  | 1563 | ImplicitOutputs: implicitOutputs, | 
|  | 1564 | Args: map[string]string{ | 
| Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1565 | "outDir":            android.PathForModuleOut(ctx, "out").String(), | 
|  | 1566 | "srcJarDir":         android.PathForModuleOut(ctx, "srcjars").String(), | 
|  | 1567 | "stubsDir":          android.PathForModuleOut(ctx, "stubsDir").String(), | 
|  | 1568 | "srcJars":           strings.Join(d.Javadoc.srcJars.Strings(), " "), | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1569 | "javaVersion":       javaVersion, | 
| Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1570 | "bootclasspathArgs": bootclasspathArgs, | 
|  | 1571 | "classpathArgs":     classpathArgs, | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1572 | "sourcepathArgs":    sourcepathArgs, | 
|  | 1573 | "opts":              opts, | 
| Nan Zhang | 86d2d55 | 2018-08-09 15:33:27 -0700 | [diff] [blame] | 1574 | }, | 
|  | 1575 | }) | 
|  | 1576 | } | 
|  | 1577 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1578 | func (d *Droidstubs) transformCheckApi(ctx android.ModuleContext, | 
|  | 1579 | apiFile, removedApiFile android.Path, implicits android.Paths, | 
|  | 1580 | javaVersion, bootclasspathArgs, classpathArgs, sourcepathArgs, opts, msg string, | 
| Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1581 | output android.WritablePath) { | 
|  | 1582 | ctx.Build(pctx, android.BuildParams{ | 
|  | 1583 | Rule:        metalavaApiCheck, | 
|  | 1584 | Description: "Metalava Check API", | 
|  | 1585 | Output:      output, | 
|  | 1586 | Inputs:      d.Javadoc.srcFiles, | 
|  | 1587 | Implicits: append(android.Paths{apiFile, removedApiFile, d.apiFile, d.removedApiFile}, | 
|  | 1588 | implicits...), | 
|  | 1589 | Args: map[string]string{ | 
| Nan Zhang | 3ffc352 | 2018-11-29 10:42:47 -0800 | [diff] [blame] | 1590 | "srcJarDir":         android.PathForModuleOut(ctx, "apicheck-srcjars").String(), | 
| Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1591 | "srcJars":           strings.Join(d.Javadoc.srcJars.Strings(), " "), | 
|  | 1592 | "javaVersion":       javaVersion, | 
|  | 1593 | "bootclasspathArgs": bootclasspathArgs, | 
|  | 1594 | "classpathArgs":     classpathArgs, | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1595 | "sourcepathArgs":    sourcepathArgs, | 
| Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1596 | "opts":              opts, | 
|  | 1597 | "msg":               msg, | 
|  | 1598 | }, | 
|  | 1599 | }) | 
|  | 1600 | } | 
|  | 1601 |  | 
| Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1602 | func (d *Droidstubs) transformJdiff(ctx android.ModuleContext, implicits android.Paths, | 
|  | 1603 | implicitOutputs android.WritablePaths, | 
|  | 1604 | bootclasspathArgs, classpathArgs, sourcepathArgs, opts string) { | 
|  | 1605 | ctx.Build(pctx, android.BuildParams{ | 
|  | 1606 | Rule:            javadoc, | 
|  | 1607 | Description:     "Jdiff", | 
|  | 1608 | Output:          d.jdiffStubsSrcJar, | 
|  | 1609 | Inputs:          d.Javadoc.srcFiles, | 
|  | 1610 | Implicits:       implicits, | 
|  | 1611 | ImplicitOutputs: implicitOutputs, | 
|  | 1612 | Args: map[string]string{ | 
| Nan Zhang | 23a1ba6 | 2018-09-19 11:19:39 -0700 | [diff] [blame] | 1613 | "outDir":            android.PathForModuleOut(ctx, "jdiff-out").String(), | 
|  | 1614 | "srcJarDir":         android.PathForModuleOut(ctx, "jdiff-srcjars").String(), | 
|  | 1615 | "stubsDir":          android.PathForModuleOut(ctx, "jdiff-stubsDir").String(), | 
| Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1616 | "srcJars":           strings.Join(d.Javadoc.srcJars.Strings(), " "), | 
|  | 1617 | "opts":              opts, | 
|  | 1618 | "bootclasspathArgs": bootclasspathArgs, | 
|  | 1619 | "classpathArgs":     classpathArgs, | 
|  | 1620 | "sourcepathArgs":    sourcepathArgs, | 
|  | 1621 | "docZip":            d.jdiffDocZip.String(), | 
|  | 1622 | }, | 
|  | 1623 | }) | 
|  | 1624 | } | 
|  | 1625 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1626 | func (d *Droidstubs) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1627 | deps := d.Javadoc.collectDeps(ctx) | 
|  | 1628 |  | 
|  | 1629 | javaVersion := getJavaVersion(ctx, String(d.Javadoc.properties.Java_version), sdkContext(d)) | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1630 |  | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1631 | var implicits android.Paths | 
|  | 1632 | implicits = append(implicits, d.Javadoc.srcJars...) | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1633 | implicits = append(implicits, d.Javadoc.argFiles...) | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1634 |  | 
|  | 1635 | var implicitOutputs android.WritablePaths | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1636 | for _, o := range d.Javadoc.properties.Out { | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1637 | implicitOutputs = append(implicitOutputs, android.PathForModuleGen(ctx, o)) | 
|  | 1638 | } | 
|  | 1639 |  | 
|  | 1640 | flags, err := d.initBuilderFlags(ctx, &implicits, deps) | 
| Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1641 | metalavaCheckApiImplicits := implicits | 
| Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1642 | jdiffImplicits := implicits | 
|  | 1643 |  | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1644 | if err != nil { | 
|  | 1645 | return | 
|  | 1646 | } | 
|  | 1647 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1648 | flags.metalavaStubsFlags = d.collectStubsFlags(ctx, &implicitOutputs) | 
| Nan Zhang | dee152b | 2018-12-26 16:06:37 -0800 | [diff] [blame] | 1649 | flags.metalavaAnnotationsFlags, flags.metalavaMergeAnnoDirFlags = | 
|  | 1650 | d.collectAnnotationsFlags(ctx, &implicits, &implicitOutputs) | 
| Neil Fuller | b2f14ec | 2018-10-21 22:13:19 +0100 | [diff] [blame] | 1651 | flags.metalavaInclusionAnnotationsFlags = d.collectInclusionAnnotationsFlags(ctx, &implicits, &implicitOutputs) | 
| Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1652 | flags.metalavaApiLevelsAnnotationsFlags = d.collectAPILevelsAnnotationsFlags(ctx, &implicits, &implicitOutputs) | 
| Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1653 | flags.metalavaApiToXmlFlags = d.collectApiToXmlFlags(ctx, &implicits, &implicitOutputs) | 
|  | 1654 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1655 | if strings.Contains(d.Javadoc.args, "--generate-documentation") { | 
|  | 1656 | // Currently Metalava have the ability to invoke Javadoc in a seperate process. | 
|  | 1657 | // Pass "-nodocs" to suppress the Javadoc invocation when Metalava receives | 
|  | 1658 | // "--generate-documentation" arg. This is not needed when Metalava removes this feature. | 
|  | 1659 | d.Javadoc.args = d.Javadoc.args + " -nodocs " | 
| Nan Zhang | 79614d1 | 2018-04-19 18:03:39 -0700 | [diff] [blame] | 1660 | } | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1661 | d.transformMetalava(ctx, implicits, implicitOutputs, javaVersion, | 
|  | 1662 | flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, | 
| Neil Fuller | b2f14ec | 2018-10-21 22:13:19 +0100 | [diff] [blame] | 1663 | flags.metalavaStubsFlags+flags.metalavaAnnotationsFlags+flags.metalavaInclusionAnnotationsFlags+ | 
| Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1664 | flags.metalavaApiLevelsAnnotationsFlags+flags.metalavaApiToXmlFlags+" "+d.Javadoc.args) | 
| Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1665 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1666 | if apiCheckEnabled(d.properties.Check_api.Current, "current") && | 
|  | 1667 | !ctx.Config().IsPdkBuild() { | 
| Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1668 | apiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Api_file), | 
|  | 1669 | "check_api.current.api_file") | 
|  | 1670 | removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Current.Removed_api_file), | 
|  | 1671 | "check_api.current_removed_api_file") | 
|  | 1672 |  | 
| Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1673 | d.checkCurrentApiTimestamp = android.PathForModuleOut(ctx, "check_current_api.timestamp") | 
| Neil Fuller | b2f14ec | 2018-10-21 22:13:19 +0100 | [diff] [blame] | 1674 | opts := " " + d.Javadoc.args + " --check-compatibility:api:current " + apiFile.String() + | 
|  | 1675 | " --check-compatibility:removed:current " + removedApiFile.String() + | 
| Nan Zhang | dee152b | 2018-12-26 16:06:37 -0800 | [diff] [blame] | 1676 | flags.metalavaInclusionAnnotationsFlags + flags.metalavaMergeAnnoDirFlags + " " | 
| Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1677 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1678 | d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits, | 
|  | 1679 | javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, | 
|  | 1680 | fmt.Sprintf(`\n******************************\n`+ | 
|  | 1681 | `You have tried to change the API from what has been previously approved.\n\n`+ | 
|  | 1682 | `To make these errors go away, you have two choices:\n`+ | 
|  | 1683 | `   1. You can add '@hide' javadoc comments to the methods, etc. listed in the\n`+ | 
|  | 1684 | `      errors above.\n\n`+ | 
|  | 1685 | `   2. You can update current.txt by executing the following command:\n`+ | 
|  | 1686 | `         make %s-update-current-api\n\n`+ | 
|  | 1687 | `      To submit the revised current.txt to the main Android repository,\n`+ | 
|  | 1688 | `      you will need approval.\n`+ | 
|  | 1689 | `******************************\n`, ctx.ModuleName()), | 
|  | 1690 | d.checkCurrentApiTimestamp) | 
| Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1691 |  | 
|  | 1692 | d.updateCurrentApiTimestamp = android.PathForModuleOut(ctx, "update_current_api.timestamp") | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1693 | transformUpdateApi(ctx, apiFile, removedApiFile, d.apiFile, d.removedApiFile, | 
|  | 1694 | d.updateCurrentApiTimestamp) | 
| Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1695 | } | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1696 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1697 | if apiCheckEnabled(d.properties.Check_api.Last_released, "last_released") && | 
|  | 1698 | !ctx.Config().IsPdkBuild() { | 
| Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1699 | apiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Api_file), | 
|  | 1700 | "check_api.last_released.api_file") | 
|  | 1701 | removedApiFile := ctx.ExpandSource(String(d.properties.Check_api.Last_released.Removed_api_file), | 
|  | 1702 | "check_api.last_released.removed_api_file") | 
|  | 1703 |  | 
| Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1704 | d.checkLastReleasedApiTimestamp = android.PathForModuleOut(ctx, "check_last_released_api.timestamp") | 
| Neil Fuller | b2f14ec | 2018-10-21 22:13:19 +0100 | [diff] [blame] | 1705 | opts := " " + d.Javadoc.args + " --check-compatibility:api:released " + apiFile.String() + | 
|  | 1706 | flags.metalavaInclusionAnnotationsFlags + " --check-compatibility:removed:released " + | 
| Nan Zhang | dee152b | 2018-12-26 16:06:37 -0800 | [diff] [blame] | 1707 | removedApiFile.String() + flags.metalavaMergeAnnoDirFlags + " " | 
| Nan Zhang | 2760dfc | 2018-08-24 17:32:54 +0000 | [diff] [blame] | 1708 |  | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1709 | d.transformCheckApi(ctx, apiFile, removedApiFile, metalavaCheckApiImplicits, | 
|  | 1710 | javaVersion, flags.bootClasspathArgs, flags.classpathArgs, flags.sourcepathArgs, opts, | 
|  | 1711 | `\n******************************\n`+ | 
|  | 1712 | `You have tried to change the API from what has been previously released in\n`+ | 
|  | 1713 | `an SDK.  Please fix the errors listed above.\n`+ | 
|  | 1714 | `******************************\n`, | 
|  | 1715 | d.checkLastReleasedApiTimestamp) | 
| Nan Zhang | 61819ce | 2018-05-04 18:49:16 -0700 | [diff] [blame] | 1716 | } | 
| Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1717 |  | 
| Pete Gillin | 581d608 | 2018-10-22 15:55:04 +0100 | [diff] [blame] | 1718 | if String(d.properties.Check_nullability_warnings) != "" { | 
|  | 1719 | if d.nullabilityWarningsFile == nil { | 
|  | 1720 | ctx.PropertyErrorf("check_nullability_warnings", | 
|  | 1721 | "Cannot specify check_nullability_warnings unless validating nullability") | 
|  | 1722 | } | 
|  | 1723 | checkNullabilityWarnings := ctx.ExpandSource(String(d.properties.Check_nullability_warnings), | 
|  | 1724 | "check_nullability_warnings") | 
|  | 1725 | d.checkNullabilityWarningsTimestamp = android.PathForModuleOut(ctx, "check_nullability_warnings.timestamp") | 
|  | 1726 | msg := fmt.Sprintf(`\n******************************\n`+ | 
|  | 1727 | `The warnings encountered during nullability annotation validation did\n`+ | 
|  | 1728 | `not match the checked in file of expected warnings. The diffs are shown\n`+ | 
|  | 1729 | `above. You have two options:\n`+ | 
|  | 1730 | `   1. Resolve the differences by editing the nullability annotations.\n`+ | 
|  | 1731 | `   2. Update the file of expected warnings by running:\n`+ | 
|  | 1732 | `         cp %s %s\n`+ | 
|  | 1733 | `       and submitting the updated file as part of your change.`, | 
|  | 1734 | d.nullabilityWarningsFile, checkNullabilityWarnings) | 
|  | 1735 | ctx.Build(pctx, android.BuildParams{ | 
|  | 1736 | Rule:        nullabilityWarningsCheck, | 
|  | 1737 | Description: "Nullability Warnings Check", | 
|  | 1738 | Output:      d.checkNullabilityWarningsTimestamp, | 
|  | 1739 | Implicits:   android.Paths{checkNullabilityWarnings, d.nullabilityWarningsFile}, | 
|  | 1740 | Args: map[string]string{ | 
|  | 1741 | "expected": checkNullabilityWarnings.String(), | 
|  | 1742 | "actual":   d.nullabilityWarningsFile.String(), | 
|  | 1743 | "msg":      msg, | 
|  | 1744 | }, | 
|  | 1745 | }) | 
|  | 1746 | } | 
|  | 1747 |  | 
| Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1748 | if Bool(d.properties.Jdiff_enabled) && !ctx.Config().IsPdkBuild() { | 
|  | 1749 |  | 
| Nan Zhang | 86b0620 | 2018-09-21 17:09:21 -0700 | [diff] [blame] | 1750 | // Please sync with android-api-council@ before making any changes for the name of jdiffDocZip below | 
|  | 1751 | // since there's cron job downstream that fetch this .zip file periodically. | 
|  | 1752 | // See b/116221385 for reference. | 
| Nan Zhang | 71bbe63 | 2018-09-17 14:32:21 -0700 | [diff] [blame] | 1753 | d.jdiffDocZip = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-docs.zip") | 
|  | 1754 | d.jdiffStubsSrcJar = android.PathForModuleOut(ctx, ctx.ModuleName()+"-"+"jdiff-stubs.srcjar") | 
|  | 1755 |  | 
|  | 1756 | var jdiffImplicitOutputs android.WritablePaths | 
|  | 1757 | jdiffImplicitOutputs = append(jdiffImplicitOutputs, d.jdiffDocZip) | 
|  | 1758 |  | 
|  | 1759 | jdiff := android.PathForOutput(ctx, "host", ctx.Config().PrebuiltOS(), "framework", "jdiff.jar") | 
|  | 1760 | jdiffImplicits = append(jdiffImplicits, android.Paths{jdiff, d.apiXmlFile, d.lastReleasedApiXmlFile}...) | 
|  | 1761 |  | 
|  | 1762 | opts := " -encoding UTF-8 -source 1.8 -J-Xmx1600m -XDignore.symbol.file " + | 
|  | 1763 | "-doclet jdiff.JDiff -docletpath " + jdiff.String() + " -quiet " + | 
|  | 1764 | "-newapi " + strings.TrimSuffix(d.apiXmlFile.Base(), d.apiXmlFile.Ext()) + | 
|  | 1765 | " -newapidir " + filepath.Dir(d.apiXmlFile.String()) + | 
|  | 1766 | " -oldapi " + strings.TrimSuffix(d.lastReleasedApiXmlFile.Base(), d.lastReleasedApiXmlFile.Ext()) + | 
|  | 1767 | " -oldapidir " + filepath.Dir(d.lastReleasedApiXmlFile.String()) | 
|  | 1768 |  | 
|  | 1769 | d.transformJdiff(ctx, jdiffImplicits, jdiffImplicitOutputs, flags.bootClasspathArgs, flags.classpathArgs, | 
|  | 1770 | flags.sourcepathArgs, opts) | 
|  | 1771 | } | 
| Nan Zhang | 581fd21 | 2018-01-10 16:06:12 -0800 | [diff] [blame] | 1772 | } | 
| Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1773 |  | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1774 | // | 
| Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1775 | // Exported Droiddoc Directory | 
| Nan Zhang | a40da04 | 2018-08-01 12:48:00 -0700 | [diff] [blame] | 1776 | // | 
| Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1777 | var droiddocTemplateTag = dependencyTag{name: "droiddoc-template"} | 
| Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1778 | var metalavaMergeAnnotationsDirTag = dependencyTag{name: "metalava-merge-annotations-dir"} | 
| Pete Gillin | 7716790 | 2018-09-19 18:16:26 +0100 | [diff] [blame] | 1779 | var metalavaMergeInclusionAnnotationsDirTag = dependencyTag{name: "metalava-merge-inclusion-annotations-dir"} | 
| Nan Zhang | 9c69a12 | 2018-08-22 10:22:08 -0700 | [diff] [blame] | 1780 | var metalavaAPILevelsAnnotationsDirTag = dependencyTag{name: "metalava-api-levels-annotations-dir"} | 
| Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1781 |  | 
| Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1782 | type ExportedDroiddocDirProperties struct { | 
|  | 1783 | // path to the directory containing Droiddoc related files. | 
| Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1784 | Path *string | 
|  | 1785 | } | 
|  | 1786 |  | 
| Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1787 | type ExportedDroiddocDir struct { | 
| Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1788 | android.ModuleBase | 
|  | 1789 |  | 
| Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1790 | properties ExportedDroiddocDirProperties | 
| Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1791 |  | 
|  | 1792 | deps android.Paths | 
|  | 1793 | dir  android.Path | 
|  | 1794 | } | 
|  | 1795 |  | 
| Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1796 | func ExportedDroiddocDirFactory() android.Module { | 
|  | 1797 | module := &ExportedDroiddocDir{} | 
| Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1798 | module.AddProperties(&module.properties) | 
|  | 1799 | android.InitAndroidModule(module) | 
|  | 1800 | return module | 
|  | 1801 | } | 
|  | 1802 |  | 
| Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1803 | func (d *ExportedDroiddocDir) DepsMutator(android.BottomUpMutatorContext) {} | 
| Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1804 |  | 
| Nan Zhang | f4936b0 | 2018-08-01 15:00:28 -0700 | [diff] [blame] | 1805 | func (d *ExportedDroiddocDir) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
| Dan Willemsen | cc09097 | 2018-02-26 14:33:31 -0800 | [diff] [blame] | 1806 | path := android.PathForModuleSrc(ctx, String(d.properties.Path)) | 
|  | 1807 | d.dir = path | 
|  | 1808 | d.deps = ctx.Glob(path.Join(ctx, "**/*").String(), nil) | 
|  | 1809 | } | 
| Nan Zhang | b2b33de | 2018-02-23 11:18:47 -0800 | [diff] [blame] | 1810 |  | 
|  | 1811 | // | 
|  | 1812 | // Defaults | 
|  | 1813 | // | 
|  | 1814 | type DocDefaults struct { | 
|  | 1815 | android.ModuleBase | 
|  | 1816 | android.DefaultsModuleBase | 
|  | 1817 | } | 
|  | 1818 |  | 
|  | 1819 | func (*DocDefaults) GenerateAndroidBuildActions(ctx android.ModuleContext) { | 
|  | 1820 | } | 
|  | 1821 |  | 
|  | 1822 | func (d *DocDefaults) DepsMutator(ctx android.BottomUpMutatorContext) { | 
|  | 1823 | } | 
|  | 1824 |  | 
|  | 1825 | func DocDefaultsFactory() android.Module { | 
|  | 1826 | module := &DocDefaults{} | 
|  | 1827 |  | 
|  | 1828 | module.AddProperties( | 
|  | 1829 | &JavadocProperties{}, | 
|  | 1830 | &DroiddocProperties{}, | 
|  | 1831 | ) | 
|  | 1832 |  | 
|  | 1833 | android.InitDefaultsModule(module) | 
|  | 1834 |  | 
|  | 1835 | return module | 
|  | 1836 | } | 
| Nan Zhang | 1598a9e | 2018-09-04 17:14:32 -0700 | [diff] [blame] | 1837 |  | 
|  | 1838 | func StubsDefaultsFactory() android.Module { | 
|  | 1839 | module := &DocDefaults{} | 
|  | 1840 |  | 
|  | 1841 | module.AddProperties( | 
|  | 1842 | &JavadocProperties{}, | 
|  | 1843 | &DroidstubsProperties{}, | 
|  | 1844 | ) | 
|  | 1845 |  | 
|  | 1846 | android.InitDefaultsModule(module) | 
|  | 1847 |  | 
|  | 1848 | return module | 
|  | 1849 | } |