Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 1 | // Copyright 2015 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 | // This file generates the final rules for compiling all Java. All properties related to |
| 18 | // compiling should have been translated into javaBuilderFlags or another argument to the Transform* |
| 19 | // functions. |
| 20 | |
| 21 | import ( |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 22 | "path/filepath" |
| 23 | "strconv" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 24 | "strings" |
| 25 | |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 26 | "github.com/google/blueprint" |
Colin Cross | fe4bc36 | 2018-09-12 10:02:13 -0700 | [diff] [blame] | 27 | "github.com/google/blueprint/proptools" |
Colin Cross | fee57cb | 2017-09-05 13:16:45 -0700 | [diff] [blame] | 28 | |
| 29 | "android/soong/android" |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 30 | ) |
| 31 | |
| 32 | var ( |
Colin Cross | 635c3b0 | 2016-05-18 15:37:25 -0700 | [diff] [blame] | 33 | pctx = android.NewPackageContext("android/soong/java") |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 34 | |
| 35 | // Compiling java is not conducive to proper dependency tracking. The path-matches-class-name |
| 36 | // requirement leads to unpredictable generated source file names, and a single .java file |
| 37 | // will get compiled into multiple .class files if it contains inner classes. To work around |
Colin Cross | f7eac7a | 2018-02-08 12:48:39 -0800 | [diff] [blame] | 38 | // this, all java rules write into separate directories and then are combined into a .jar file |
| 39 | // (if the rule produces .class files) or a .srcjar file (if the rule produces .java files). |
| 40 | // .srcjar files are unzipped into a temporary directory when compiled with javac. |
Colin Cross | 1ec3fce | 2020-03-05 12:43:14 -0800 | [diff] [blame] | 41 | // TODO(b/143658984): goma can't handle the --system argument to javac. |
| 42 | javac = pctx.AndroidRemoteStaticRule("javac", android.RemoteRuleSupports{Goma: false, RBE: true, RBEFlag: android.RBE_JAVAC}, |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 43 | blueprint.RuleParams{ |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 44 | Command: `rm -rf "$outDir" "$annoDir" "$srcJarDir" && mkdir -p "$outDir" "$annoDir" "$srcJarDir" && ` + |
Colin Cross | 436b765 | 2018-03-15 16:24:10 -0700 | [diff] [blame] | 45 | `${config.ZipSyncCmd} -d $srcJarDir -l $srcJarDir/list -f "*.java" $srcJars && ` + |
Sundong Ahn | 24a099c | 2018-06-28 14:53:20 +0900 | [diff] [blame] | 46 | `(if [ -s $srcJarDir/list ] || [ -s $out.rsp ] ; then ` + |
Sasha Smundak | 26c6d9e | 2019-06-11 13:30:13 -0700 | [diff] [blame] | 47 | `${config.SoongJavacWrapper} ${config.JavacWrapper}${config.JavacCmd} ` + |
| 48 | `${config.JavacHeapFlags} ${config.JavacVmFlags} ${config.CommonJdkFlags} ` + |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 49 | `$processorpath $processor $javacFlags $bootClasspath $classpath ` + |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 50 | `-source $javaVersion -target $javaVersion ` + |
Sundong Ahn | 24a099c | 2018-06-28 14:53:20 +0900 | [diff] [blame] | 51 | `-d $outDir -s $annoDir @$out.rsp @$srcJarDir/list ; fi ) && ` + |
Colin Cross | 44c29a8 | 2019-01-24 16:36:57 -0800 | [diff] [blame] | 52 | `${config.SoongZipCmd} -jar -o $out -C $outDir -D $outDir && ` + |
| 53 | `rm -rf "$srcJarDir"`, |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 54 | CommandDeps: []string{ |
| 55 | "${config.JavacCmd}", |
| 56 | "${config.SoongZipCmd}", |
Colin Cross | 436b765 | 2018-03-15 16:24:10 -0700 | [diff] [blame] | 57 | "${config.ZipSyncCmd}", |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 58 | }, |
Colin Cross | a482065 | 2017-10-17 13:56:52 -0700 | [diff] [blame] | 59 | CommandOrderOnly: []string{"${config.SoongJavacWrapper}"}, |
| 60 | Rspfile: "$out.rsp", |
| 61 | RspfileContent: "$in", |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 62 | }, |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 63 | "javacFlags", "bootClasspath", "classpath", "processorpath", "processor", "srcJars", "srcJarDir", |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 64 | "outDir", "annoDir", "javaVersion") |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 65 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 66 | _ = pctx.VariableFunc("kytheCorpus", |
| 67 | func(ctx android.PackageVarContext) string { return ctx.Config().XrefCorpusName() }) |
Sasha Smundak | 6c2d4f9 | 2020-01-09 17:34:23 -0800 | [diff] [blame] | 68 | _ = pctx.VariableFunc("kytheCuEncoding", |
| 69 | func(ctx android.PackageVarContext) string { return ctx.Config().XrefCuEncoding() }) |
Sasha Smundak | 6514364 | 2019-09-26 20:14:28 -0700 | [diff] [blame] | 70 | _ = pctx.SourcePathVariable("kytheVnames", "build/soong/vnames.json") |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 71 | // Run it with -add-opens=java.base/java.nio=ALL-UNNAMED to avoid JDK9's warning about |
| 72 | // "Illegal reflective access by com.google.protobuf.Utf8$UnsafeProcessor ... |
| 73 | // to field java.nio.Buffer.address" |
| 74 | kytheExtract = pctx.AndroidStaticRule("kythe", |
| 75 | blueprint.RuleParams{ |
| 76 | Command: `${config.ZipSyncCmd} -d $srcJarDir ` + |
| 77 | `-l $srcJarDir/list -f "*.java" $srcJars && ` + |
| 78 | `( [ ! -s $srcJarDir/list -a ! -s $out.rsp ] || ` + |
| 79 | `KYTHE_ROOT_DIRECTORY=. KYTHE_OUTPUT_FILE=$out ` + |
| 80 | `KYTHE_CORPUS=${kytheCorpus} ` + |
Sasha Smundak | 6514364 | 2019-09-26 20:14:28 -0700 | [diff] [blame] | 81 | `KYTHE_VNAMES=${kytheVnames} ` + |
Sasha Smundak | 6c2d4f9 | 2020-01-09 17:34:23 -0800 | [diff] [blame] | 82 | `KYTHE_KZIP_ENCODING=${kytheCuEncoding} ` + |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 83 | `${config.SoongJavacWrapper} ${config.JavaCmd} ` + |
| 84 | `--add-opens=java.base/java.nio=ALL-UNNAMED ` + |
| 85 | `-jar ${config.JavaKytheExtractorJar} ` + |
| 86 | `${config.JavacHeapFlags} ${config.CommonJdkFlags} ` + |
| 87 | `$processorpath $processor $javacFlags $bootClasspath $classpath ` + |
| 88 | `-source $javaVersion -target $javaVersion ` + |
| 89 | `-d $outDir -s $annoDir @$out.rsp @$srcJarDir/list)`, |
| 90 | CommandDeps: []string{ |
| 91 | "${config.JavaCmd}", |
| 92 | "${config.JavaKytheExtractorJar}", |
Sasha Smundak | 6514364 | 2019-09-26 20:14:28 -0700 | [diff] [blame] | 93 | "${kytheVnames}", |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 94 | "${config.ZipSyncCmd}", |
| 95 | }, |
| 96 | CommandOrderOnly: []string{"${config.SoongJavacWrapper}"}, |
| 97 | Rspfile: "$out.rsp", |
| 98 | RspfileContent: "$in", |
| 99 | }, |
| 100 | "javacFlags", "bootClasspath", "classpath", "processorpath", "processor", "srcJars", "srcJarDir", |
| 101 | "outDir", "annoDir", "javaVersion") |
| 102 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 103 | turbine = pctx.AndroidStaticRule("turbine", |
| 104 | blueprint.RuleParams{ |
Colin Cross | 6981f65 | 2018-03-07 15:14:50 -0800 | [diff] [blame] | 105 | Command: `rm -rf "$outDir" && mkdir -p "$outDir" && ` + |
Sasha Smundak | 26c6d9e | 2019-06-11 13:30:13 -0700 | [diff] [blame] | 106 | `${config.JavaCmd} ${config.JavaVmFlags} -jar ${config.TurbineJar} --output $out.tmp ` + |
Colin Cross | 6981f65 | 2018-03-07 15:14:50 -0800 | [diff] [blame] | 107 | `--temp_dir "$outDir" --sources @$out.rsp --source_jars $srcJars ` + |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 108 | `--javacopts ${config.CommonJdkFlags} ` + |
Colin Cross | 924a0aa | 2018-03-07 10:51:05 -0800 | [diff] [blame] | 109 | `$javacFlags -source $javaVersion -target $javaVersion -- $bootClasspath $classpath && ` + |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 110 | `${config.Ziptime} $out.tmp && ` + |
| 111 | `(if cmp -s $out.tmp $out ; then rm $out.tmp ; else mv $out.tmp $out ; fi )`, |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 112 | CommandDeps: []string{ |
| 113 | "${config.TurbineJar}", |
| 114 | "${config.JavaCmd}", |
| 115 | "${config.Ziptime}", |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 116 | }, |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 117 | Rspfile: "$out.rsp", |
| 118 | RspfileContent: "$in", |
| 119 | Restat: true, |
| 120 | }, |
Colin Cross | 6981f65 | 2018-03-07 15:14:50 -0800 | [diff] [blame] | 121 | "javacFlags", "bootClasspath", "classpath", "srcJars", "outDir", "javaVersion") |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 122 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 123 | jar = pctx.AndroidStaticRule("jar", |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 124 | blueprint.RuleParams{ |
Nan Zhang | 674dd93 | 2018-01-26 18:30:36 -0800 | [diff] [blame] | 125 | Command: `${config.SoongZipCmd} -jar -o $out @$out.rsp`, |
| 126 | CommandDeps: []string{"${config.SoongZipCmd}"}, |
| 127 | Rspfile: "$out.rsp", |
| 128 | RspfileContent: "$jarArgs", |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 129 | }, |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 130 | "jarArgs") |
| 131 | |
Colin Cross | a4f0881 | 2018-10-02 22:03:40 -0700 | [diff] [blame] | 132 | zip = pctx.AndroidStaticRule("zip", |
| 133 | blueprint.RuleParams{ |
| 134 | Command: `${config.SoongZipCmd} -o $out @$out.rsp`, |
| 135 | CommandDeps: []string{"${config.SoongZipCmd}"}, |
| 136 | Rspfile: "$out.rsp", |
| 137 | RspfileContent: "$jarArgs", |
| 138 | }, |
| 139 | "jarArgs") |
| 140 | |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 141 | combineJar = pctx.AndroidStaticRule("combineJar", |
| 142 | blueprint.RuleParams{ |
Colin Cross | f91a08c | 2018-02-07 15:41:31 -0800 | [diff] [blame] | 143 | Command: `${config.MergeZipsCmd} --ignore-duplicates -j $jarArgs $out $in`, |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 144 | CommandDeps: []string{"${config.MergeZipsCmd}"}, |
| 145 | }, |
Colin Cross | 635acc9 | 2017-09-12 22:50:46 -0700 | [diff] [blame] | 146 | "jarArgs") |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 147 | |
Colin Cross | 9d45bb7 | 2016-08-29 16:14:13 -0700 | [diff] [blame] | 148 | jarjar = pctx.AndroidStaticRule("jarjar", |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 149 | blueprint.RuleParams{ |
Sasha Smundak | 26c6d9e | 2019-06-11 13:30:13 -0700 | [diff] [blame] | 150 | Command: "${config.JavaCmd} ${config.JavaVmFlags} -jar ${config.JarjarCmd} process $rulesFile $in $out", |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 151 | CommandDeps: []string{"${config.JavaCmd}", "${config.JarjarCmd}", "$rulesFile"}, |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 152 | }, |
| 153 | "rulesFile") |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 154 | |
Vladimir Marko | 0975ee0 | 2019-04-02 10:29:55 +0100 | [diff] [blame] | 155 | packageCheck = pctx.AndroidStaticRule("packageCheck", |
| 156 | blueprint.RuleParams{ |
| 157 | Command: "rm -f $out && " + |
| 158 | "${config.PackageCheckCmd} $in $packages && " + |
| 159 | "touch $out", |
| 160 | CommandDeps: []string{"${config.PackageCheckCmd}"}, |
| 161 | }, |
| 162 | "packages") |
| 163 | |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 164 | jetifier = pctx.AndroidStaticRule("jetifier", |
| 165 | blueprint.RuleParams{ |
Sasha Smundak | 26c6d9e | 2019-06-11 13:30:13 -0700 | [diff] [blame] | 166 | Command: "${config.JavaCmd} ${config.JavaVmFlags} -jar ${config.JetifierJar} -l error -o $out -i $in", |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 167 | CommandDeps: []string{"${config.JavaCmd}", "${config.JetifierJar}"}, |
| 168 | }, |
| 169 | ) |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 170 | |
| 171 | zipalign = pctx.AndroidStaticRule("zipalign", |
| 172 | blueprint.RuleParams{ |
Colin Cross | e4246ab | 2019-02-05 21:55:21 -0800 | [diff] [blame] | 173 | Command: "if ! ${config.ZipAlign} -c -p 4 $in > /dev/null; then " + |
| 174 | "${config.ZipAlign} -f -p 4 $in $out; " + |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 175 | "else " + |
| 176 | "cp -f $in $out; " + |
| 177 | "fi", |
| 178 | CommandDeps: []string{"${config.ZipAlign}"}, |
| 179 | }, |
| 180 | ) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 181 | ) |
| 182 | |
| 183 | func init() { |
Colin Cross | cc0ce80 | 2019-04-02 16:14:11 -0700 | [diff] [blame] | 184 | pctx.Import("android/soong/android") |
Colin Cross | 6416271 | 2017-08-08 13:17:59 -0700 | [diff] [blame] | 185 | pctx.Import("android/soong/java/config") |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 186 | } |
| 187 | |
| 188 | type javaBuilderFlags struct { |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 189 | javacFlags string |
| 190 | bootClasspath classpath |
| 191 | classpath classpath |
| 192 | java9Classpath classpath |
| 193 | processorPath classpath |
Colin Cross | 5a11686 | 2020-04-22 11:44:34 -0700 | [diff] [blame^] | 194 | processors []string |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 195 | systemModules *systemModules |
| 196 | aidlFlags string |
| 197 | aidlDeps android.Paths |
| 198 | javaVersion javaVersion |
Colin Cross | 6af17aa | 2017-09-20 12:59:05 -0700 | [diff] [blame] | 199 | |
Andreas Gampe | f3e5b55 | 2018-01-22 21:27:21 -0800 | [diff] [blame] | 200 | errorProneExtraJavacFlags string |
Colin Cross | 6654810 | 2018-06-19 22:47:35 -0700 | [diff] [blame] | 201 | errorProneProcessorPath classpath |
Andreas Gampe | f3e5b55 | 2018-01-22 21:27:21 -0800 | [diff] [blame] | 202 | |
Colin Cross | 93e8595 | 2017-08-15 13:34:18 -0700 | [diff] [blame] | 203 | kotlincFlags string |
| 204 | kotlincClasspath classpath |
| 205 | |
Colin Cross | 19878da | 2019-03-28 14:45:07 -0700 | [diff] [blame] | 206 | proto android.ProtoFlags |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 207 | } |
| 208 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 209 | func TransformJavaToClasses(ctx android.ModuleContext, outputFile android.WritablePath, shardIdx int, |
| 210 | srcFiles, srcJars android.Paths, flags javaBuilderFlags, deps android.Paths) { |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 211 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 212 | // Compile java sources into .class files |
| 213 | desc := "javac" |
| 214 | if shardIdx >= 0 { |
| 215 | desc += strconv.Itoa(shardIdx) |
| 216 | } |
| 217 | |
Colin Cross | 6654810 | 2018-06-19 22:47:35 -0700 | [diff] [blame] | 218 | transformJavaToClasses(ctx, outputFile, shardIdx, srcFiles, srcJars, flags, deps, "javac", desc) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 219 | } |
| 220 | |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 221 | func RunErrorProne(ctx android.ModuleContext, outputFile android.WritablePath, |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 222 | srcFiles, srcJars android.Paths, flags javaBuilderFlags) { |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 223 | |
Colin Cross | 6654810 | 2018-06-19 22:47:35 -0700 | [diff] [blame] | 224 | flags.processorPath = append(flags.errorProneProcessorPath, flags.processorPath...) |
Colin Cross | fee57cb | 2017-09-05 13:16:45 -0700 | [diff] [blame] | 225 | |
Andreas Gampe | f3e5b55 | 2018-01-22 21:27:21 -0800 | [diff] [blame] | 226 | if len(flags.errorProneExtraJavacFlags) > 0 { |
| 227 | if len(flags.javacFlags) > 0 { |
Colin Cross | 6654810 | 2018-06-19 22:47:35 -0700 | [diff] [blame] | 228 | flags.javacFlags += " " + flags.errorProneExtraJavacFlags |
Andreas Gampe | f3e5b55 | 2018-01-22 21:27:21 -0800 | [diff] [blame] | 229 | } else { |
| 230 | flags.javacFlags = flags.errorProneExtraJavacFlags |
| 231 | } |
| 232 | } |
| 233 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 234 | transformJavaToClasses(ctx, outputFile, -1, srcFiles, srcJars, flags, nil, |
Colin Cross | 6654810 | 2018-06-19 22:47:35 -0700 | [diff] [blame] | 235 | "errorprone", "errorprone") |
Colin Cross | 070879e | 2017-10-11 11:21:07 -0700 | [diff] [blame] | 236 | } |
| 237 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 238 | // Emits the rule to generate Xref input file (.kzip file) for the given set of source files and source jars |
| 239 | // to compile with given set of builder flags, etc. |
Colin Cross | 3b706fd | 2019-09-05 16:44:18 -0700 | [diff] [blame] | 240 | func emitXrefRule(ctx android.ModuleContext, xrefFile android.WritablePath, idx int, |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 241 | srcFiles, srcJars android.Paths, |
Colin Cross | 3b706fd | 2019-09-05 16:44:18 -0700 | [diff] [blame] | 242 | flags javaBuilderFlags, deps android.Paths) { |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 243 | |
| 244 | deps = append(deps, srcJars...) |
Sasha Smundak | 09950a4 | 2019-11-04 16:29:45 -0800 | [diff] [blame] | 245 | classpath := flags.classpath |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 246 | |
| 247 | var bootClasspath string |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 248 | if flags.javaVersion.usesJavaModules() { |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 249 | var systemModuleDeps android.Paths |
| 250 | bootClasspath, systemModuleDeps = flags.systemModules.FormJavaSystemModulesPath(ctx.Device()) |
| 251 | deps = append(deps, systemModuleDeps...) |
Sasha Smundak | 09950a4 | 2019-11-04 16:29:45 -0800 | [diff] [blame] | 252 | classpath = append(flags.java9Classpath, classpath...) |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 253 | } else { |
| 254 | deps = append(deps, flags.bootClasspath...) |
| 255 | if len(flags.bootClasspath) == 0 && ctx.Device() { |
| 256 | // explicitly specify -bootclasspath "" if the bootclasspath is empty to |
| 257 | // ensure java does not fall back to the default bootclasspath. |
| 258 | bootClasspath = `-bootclasspath ""` |
| 259 | } else { |
| 260 | bootClasspath = flags.bootClasspath.FormJavaClassPath("-bootclasspath") |
| 261 | } |
| 262 | } |
| 263 | |
Sasha Smundak | 09950a4 | 2019-11-04 16:29:45 -0800 | [diff] [blame] | 264 | deps = append(deps, classpath...) |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 265 | deps = append(deps, flags.processorPath...) |
| 266 | |
| 267 | processor := "-proc:none" |
Colin Cross | 5a11686 | 2020-04-22 11:44:34 -0700 | [diff] [blame^] | 268 | if len(flags.processors) > 0 { |
| 269 | processor = "-processor " + strings.Join(flags.processors, ",") |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 270 | } |
| 271 | |
Colin Cross | 3b706fd | 2019-09-05 16:44:18 -0700 | [diff] [blame] | 272 | intermediatesDir := "xref" |
| 273 | if idx >= 0 { |
| 274 | intermediatesDir += strconv.Itoa(idx) |
| 275 | } |
| 276 | |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 277 | ctx.Build(pctx, |
| 278 | android.BuildParams{ |
| 279 | Rule: kytheExtract, |
| 280 | Description: "Xref Java extractor", |
| 281 | Output: xrefFile, |
| 282 | Inputs: srcFiles, |
| 283 | Implicits: deps, |
| 284 | Args: map[string]string{ |
| 285 | "annoDir": android.PathForModuleOut(ctx, intermediatesDir, "anno").String(), |
| 286 | "bootClasspath": bootClasspath, |
Sasha Smundak | 09950a4 | 2019-11-04 16:29:45 -0800 | [diff] [blame] | 287 | "classpath": classpath.FormJavaClassPath("-classpath"), |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 288 | "javacFlags": flags.javacFlags, |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 289 | "javaVersion": flags.javaVersion.String(), |
Sasha Smundak | 2a4549e | 2018-11-05 16:49:08 -0800 | [diff] [blame] | 290 | "outDir": android.PathForModuleOut(ctx, "javac", "classes.xref").String(), |
| 291 | "processorpath": flags.processorPath.FormJavaClassPath("-processorpath"), |
| 292 | "processor": processor, |
| 293 | "srcJarDir": android.PathForModuleOut(ctx, intermediatesDir, "srcjars.xref").String(), |
| 294 | "srcJars": strings.Join(srcJars.Strings(), " "), |
| 295 | }, |
| 296 | }) |
| 297 | } |
| 298 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 299 | func TransformJavaToHeaderClasses(ctx android.ModuleContext, outputFile android.WritablePath, |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 300 | srcFiles, srcJars android.Paths, flags javaBuilderFlags) { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 301 | |
| 302 | var deps android.Paths |
| 303 | deps = append(deps, srcJars...) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 304 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 305 | classpath := flags.classpath |
| 306 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 307 | var bootClasspath string |
Colin Cross | bf3119e | 2019-10-28 14:25:10 -0700 | [diff] [blame] | 308 | if flags.javaVersion.usesJavaModules() { |
| 309 | var systemModuleDeps android.Paths |
| 310 | bootClasspath, systemModuleDeps = flags.systemModules.FormTurbineSystemModulesPath(ctx.Device()) |
| 311 | deps = append(deps, systemModuleDeps...) |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 312 | classpath = append(flags.java9Classpath, classpath...) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 313 | } else { |
Colin Cross | bf3119e | 2019-10-28 14:25:10 -0700 | [diff] [blame] | 314 | deps = append(deps, flags.bootClasspath...) |
| 315 | if len(flags.bootClasspath) == 0 && ctx.Device() { |
| 316 | // explicitly specify -bootclasspath "" if the bootclasspath is empty to |
| 317 | // ensure turbine does not fall back to the default bootclasspath. |
| 318 | bootClasspath = `--bootclasspath ""` |
| 319 | } else { |
Colin Cross | c2557d1 | 2019-10-31 15:22:57 -0700 | [diff] [blame] | 320 | bootClasspath = flags.bootClasspath.FormTurbineClassPath("--bootclasspath ") |
Colin Cross | bf3119e | 2019-10-28 14:25:10 -0700 | [diff] [blame] | 321 | } |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 322 | } |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 323 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 324 | deps = append(deps, classpath...) |
Colin Cross | bf3119e | 2019-10-28 14:25:10 -0700 | [diff] [blame] | 325 | deps = append(deps, flags.processorPath...) |
| 326 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 327 | ctx.Build(pctx, android.BuildParams{ |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 328 | Rule: turbine, |
| 329 | Description: "turbine", |
| 330 | Output: outputFile, |
| 331 | Inputs: srcFiles, |
| 332 | Implicits: deps, |
| 333 | Args: map[string]string{ |
| 334 | "javacFlags": flags.javacFlags, |
| 335 | "bootClasspath": bootClasspath, |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 336 | "srcJars": strings.Join(srcJars.Strings(), " "), |
Colin Cross | c2557d1 | 2019-10-31 15:22:57 -0700 | [diff] [blame] | 337 | "classpath": classpath.FormTurbineClassPath("--classpath "), |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 338 | "outDir": android.PathForModuleOut(ctx, "turbine", "classes").String(), |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 339 | "javaVersion": flags.javaVersion.String(), |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 340 | }, |
| 341 | }) |
| 342 | } |
| 343 | |
Colin Cross | 070879e | 2017-10-11 11:21:07 -0700 | [diff] [blame] | 344 | // transformJavaToClasses takes source files and converts them to a jar containing .class files. |
Colin Cross | 59149b6 | 2017-10-16 18:07:29 -0700 | [diff] [blame] | 345 | // srcFiles is a list of paths to sources, srcJars is a list of paths to jar files that contain |
| 346 | // sources. flags contains various command line flags to be passed to the compiler. |
Colin Cross | 070879e | 2017-10-11 11:21:07 -0700 | [diff] [blame] | 347 | // |
| 348 | // This method may be used for different compilers, including javac and Error Prone. The rule |
| 349 | // argument specifies which command line to use and desc sets the description of the rule that will |
| 350 | // be printed at build time. The stem argument provides the file name of the output jar, and |
| 351 | // suffix will be appended to various intermediate files and directories to avoid collisions when |
| 352 | // this function is called twice in the same module directory. |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 353 | func transformJavaToClasses(ctx android.ModuleContext, outputFile android.WritablePath, |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 354 | shardIdx int, srcFiles, srcJars android.Paths, |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 355 | flags javaBuilderFlags, deps android.Paths, |
Colin Cross | 6654810 | 2018-06-19 22:47:35 -0700 | [diff] [blame] | 356 | intermediatesDir, desc string) { |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 357 | |
Colin Cross | 59149b6 | 2017-10-16 18:07:29 -0700 | [diff] [blame] | 358 | deps = append(deps, srcJars...) |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 359 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 360 | classpath := flags.classpath |
| 361 | |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 362 | var bootClasspath string |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 363 | if flags.javaVersion.usesJavaModules() { |
Colin Cross | b77043e | 2019-07-16 13:57:13 -0700 | [diff] [blame] | 364 | var systemModuleDeps android.Paths |
| 365 | bootClasspath, systemModuleDeps = flags.systemModules.FormJavaSystemModulesPath(ctx.Device()) |
| 366 | deps = append(deps, systemModuleDeps...) |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 367 | classpath = append(flags.java9Classpath, classpath...) |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 368 | } else { |
| 369 | deps = append(deps, flags.bootClasspath...) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 370 | if len(flags.bootClasspath) == 0 && ctx.Device() { |
| 371 | // explicitly specify -bootclasspath "" if the bootclasspath is empty to |
| 372 | // ensure java does not fall back to the default bootclasspath. |
| 373 | bootClasspath = `-bootclasspath ""` |
| 374 | } else { |
| 375 | bootClasspath = flags.bootClasspath.FormJavaClassPath("-bootclasspath") |
| 376 | } |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 377 | } |
| 378 | |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 379 | deps = append(deps, classpath...) |
Colin Cross | 6a77c98 | 2018-06-19 22:43:34 -0700 | [diff] [blame] | 380 | deps = append(deps, flags.processorPath...) |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 381 | |
Colin Cross | 7788c12 | 2019-01-23 16:14:02 -0800 | [diff] [blame] | 382 | processor := "-proc:none" |
Colin Cross | 5a11686 | 2020-04-22 11:44:34 -0700 | [diff] [blame^] | 383 | if len(flags.processors) > 0 { |
| 384 | processor = "-processor " + strings.Join(flags.processors, ",") |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 385 | } |
| 386 | |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 387 | srcJarDir := "srcjars" |
| 388 | outDir := "classes" |
| 389 | annoDir := "anno" |
| 390 | if shardIdx >= 0 { |
| 391 | shardDir := "shard" + strconv.Itoa(shardIdx) |
| 392 | srcJarDir = filepath.Join(shardDir, srcJarDir) |
| 393 | outDir = filepath.Join(shardDir, outDir) |
| 394 | annoDir = filepath.Join(shardDir, annoDir) |
| 395 | } |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 396 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 6654810 | 2018-06-19 22:47:35 -0700 | [diff] [blame] | 397 | Rule: javac, |
Colin Cross | 070879e | 2017-10-11 11:21:07 -0700 | [diff] [blame] | 398 | Description: desc, |
| 399 | Output: outputFile, |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 400 | Inputs: srcFiles, |
| 401 | Implicits: deps, |
| 402 | Args: map[string]string{ |
Colin Cross | 59149b6 | 2017-10-16 18:07:29 -0700 | [diff] [blame] | 403 | "javacFlags": flags.javacFlags, |
Colin Cross | 1369cdb | 2017-09-29 17:58:17 -0700 | [diff] [blame] | 404 | "bootClasspath": bootClasspath, |
Colin Cross | 6cef481 | 2019-10-17 14:23:50 -0700 | [diff] [blame] | 405 | "classpath": classpath.FormJavaClassPath("-classpath"), |
Colin Cross | 6a77c98 | 2018-06-19 22:43:34 -0700 | [diff] [blame] | 406 | "processorpath": flags.processorPath.FormJavaClassPath("-processorpath"), |
Colin Cross | be9cdb8 | 2019-01-21 21:37:16 -0800 | [diff] [blame] | 407 | "processor": processor, |
Colin Cross | 8eadbf0 | 2017-10-24 17:46:00 -0700 | [diff] [blame] | 408 | "srcJars": strings.Join(srcJars.Strings(), " "), |
Nan Zhang | 61eaedb | 2017-11-02 13:28:15 -0700 | [diff] [blame] | 409 | "srcJarDir": android.PathForModuleOut(ctx, intermediatesDir, srcJarDir).String(), |
| 410 | "outDir": android.PathForModuleOut(ctx, intermediatesDir, outDir).String(), |
| 411 | "annoDir": android.PathForModuleOut(ctx, intermediatesDir, annoDir).String(), |
Colin Cross | 1e74385 | 2019-10-28 11:37:20 -0700 | [diff] [blame] | 412 | "javaVersion": flags.javaVersion.String(), |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 413 | }, |
| 414 | }) |
Colin Cross | c6bbef3 | 2017-08-14 14:16:06 -0700 | [diff] [blame] | 415 | } |
| 416 | |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 417 | func TransformResourcesToJar(ctx android.ModuleContext, outputFile android.WritablePath, |
| 418 | jarArgs []string, deps android.Paths) { |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 419 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 420 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 421 | Rule: jar, |
| 422 | Description: "jar", |
| 423 | Output: outputFile, |
| 424 | Implicits: deps, |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 425 | Args: map[string]string{ |
Colin Cross | 0b9f31f | 2019-02-28 11:00:01 -0800 | [diff] [blame] | 426 | "jarArgs": strings.Join(proptools.NinjaAndShellEscapeList(jarArgs), " "), |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 427 | }, |
| 428 | }) |
Colin Cross | 2fe6687 | 2015-03-30 17:20:39 -0700 | [diff] [blame] | 429 | } |
| 430 | |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 431 | func TransformJarsToJar(ctx android.ModuleContext, outputFile android.WritablePath, desc string, |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 432 | jars android.Paths, manifest android.OptionalPath, stripDirEntries bool, filesToStrip []string, |
| 433 | dirsToStrip []string) { |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 434 | |
Colin Cross | 635acc9 | 2017-09-12 22:50:46 -0700 | [diff] [blame] | 435 | var deps android.Paths |
| 436 | |
| 437 | var jarArgs []string |
| 438 | if manifest.Valid() { |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 439 | jarArgs = append(jarArgs, "-m ", manifest.String()) |
Colin Cross | 635acc9 | 2017-09-12 22:50:46 -0700 | [diff] [blame] | 440 | deps = append(deps, manifest.Path()) |
| 441 | } |
| 442 | |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 443 | for _, dir := range dirsToStrip { |
| 444 | jarArgs = append(jarArgs, "-stripDir ", dir) |
| 445 | } |
| 446 | |
| 447 | for _, file := range filesToStrip { |
| 448 | jarArgs = append(jarArgs, "-stripFile ", file) |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 449 | } |
| 450 | |
Colin Cross | 7b60cdd | 2017-12-21 13:52:58 -0800 | [diff] [blame] | 451 | // Remove any module-info.class files that may have come from prebuilt jars, they cause problems |
| 452 | // for downstream tools like desugar. |
| 453 | jarArgs = append(jarArgs, "-stripFile module-info.class") |
| 454 | |
Colin Cross | 37f6d79 | 2018-07-12 12:28:41 -0700 | [diff] [blame] | 455 | if stripDirEntries { |
Colin Cross | 635acc9 | 2017-09-12 22:50:46 -0700 | [diff] [blame] | 456 | jarArgs = append(jarArgs, "-D") |
| 457 | } |
| 458 | |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 459 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 460 | Rule: combineJar, |
Nan Zhang | ed19fc3 | 2017-10-19 13:06:22 -0700 | [diff] [blame] | 461 | Description: desc, |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 462 | Output: outputFile, |
| 463 | Inputs: jars, |
Colin Cross | 635acc9 | 2017-09-12 22:50:46 -0700 | [diff] [blame] | 464 | Implicits: deps, |
| 465 | Args: map[string]string{ |
| 466 | "jarArgs": strings.Join(jarArgs, " "), |
| 467 | }, |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 468 | }) |
Colin Cross | 0a6e007 | 2017-08-30 14:24:55 -0700 | [diff] [blame] | 469 | } |
| 470 | |
Colin Cross | e9a275b | 2017-10-16 17:09:48 -0700 | [diff] [blame] | 471 | func TransformJarJar(ctx android.ModuleContext, outputFile android.WritablePath, |
| 472 | classesJar android.Path, rulesFile android.Path) { |
Colin Cross | ae88703 | 2017-10-23 17:16:14 -0700 | [diff] [blame] | 473 | ctx.Build(pctx, android.BuildParams{ |
Colin Cross | 67a5c13 | 2017-05-09 13:45:28 -0700 | [diff] [blame] | 474 | Rule: jarjar, |
| 475 | Description: "jarjar", |
| 476 | Output: outputFile, |
| 477 | Input: classesJar, |
| 478 | Implicit: rulesFile, |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 479 | Args: map[string]string{ |
Dan Willemsen | 34cc69e | 2015-09-23 15:26:20 -0700 | [diff] [blame] | 480 | "rulesFile": rulesFile.String(), |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 481 | }, |
| 482 | }) |
Colin Cross | 65bf4f2 | 2015-04-03 16:54:17 -0700 | [diff] [blame] | 483 | } |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 484 | |
Vladimir Marko | 0975ee0 | 2019-04-02 10:29:55 +0100 | [diff] [blame] | 485 | func CheckJarPackages(ctx android.ModuleContext, outputFile android.WritablePath, |
| 486 | classesJar android.Path, permittedPackages []string) { |
| 487 | ctx.Build(pctx, android.BuildParams{ |
| 488 | Rule: packageCheck, |
| 489 | Description: "packageCheck", |
| 490 | Output: outputFile, |
| 491 | Input: classesJar, |
| 492 | Args: map[string]string{ |
| 493 | "packages": strings.Join(permittedPackages, " "), |
| 494 | }, |
| 495 | }) |
| 496 | } |
| 497 | |
Nan Zhang | 4c819fb | 2018-08-27 18:31:46 -0700 | [diff] [blame] | 498 | func TransformJetifier(ctx android.ModuleContext, outputFile android.WritablePath, |
| 499 | inputFile android.Path) { |
| 500 | ctx.Build(pctx, android.BuildParams{ |
| 501 | Rule: jetifier, |
| 502 | Description: "jetifier", |
| 503 | Output: outputFile, |
| 504 | Input: inputFile, |
| 505 | }) |
| 506 | } |
| 507 | |
Colin Cross | 094054a | 2018-10-17 15:10:48 -0700 | [diff] [blame] | 508 | func GenerateMainClassManifest(ctx android.ModuleContext, outputFile android.WritablePath, mainClass string) { |
| 509 | ctx.Build(pctx, android.BuildParams{ |
| 510 | Rule: android.WriteFile, |
| 511 | Description: "manifest", |
| 512 | Output: outputFile, |
| 513 | Args: map[string]string{ |
| 514 | "content": "Main-Class: " + mainClass + "\n", |
| 515 | }, |
| 516 | }) |
| 517 | } |
| 518 | |
Colin Cross | 43f08db | 2018-11-12 10:13:39 -0800 | [diff] [blame] | 519 | func TransformZipAlign(ctx android.ModuleContext, outputFile android.WritablePath, inputFile android.Path) { |
| 520 | ctx.Build(pctx, android.BuildParams{ |
| 521 | Rule: zipalign, |
| 522 | Description: "align", |
| 523 | Input: inputFile, |
| 524 | Output: outputFile, |
| 525 | }) |
| 526 | } |
| 527 | |
Colin Cross | 33961b5 | 2019-07-11 11:01:22 -0700 | [diff] [blame] | 528 | type classpath android.Paths |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 529 | |
Colin Cross | c2557d1 | 2019-10-31 15:22:57 -0700 | [diff] [blame] | 530 | func (x *classpath) formJoinedClassPath(optName string, sep string) string { |
Colin Cross | 8144008 | 2018-08-15 20:21:55 -0700 | [diff] [blame] | 531 | if optName != "" && !strings.HasSuffix(optName, "=") && !strings.HasSuffix(optName, " ") { |
| 532 | optName += " " |
| 533 | } |
Colin Cross | 59149b6 | 2017-10-16 18:07:29 -0700 | [diff] [blame] | 534 | if len(*x) > 0 { |
Colin Cross | c2557d1 | 2019-10-31 15:22:57 -0700 | [diff] [blame] | 535 | return optName + strings.Join(x.Strings(), sep) |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 536 | } else { |
| 537 | return "" |
| 538 | } |
| 539 | } |
Colin Cross | c2557d1 | 2019-10-31 15:22:57 -0700 | [diff] [blame] | 540 | func (x *classpath) FormJavaClassPath(optName string) string { |
| 541 | return x.formJoinedClassPath(optName, ":") |
| 542 | } |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 543 | |
Colin Cross | c2557d1 | 2019-10-31 15:22:57 -0700 | [diff] [blame] | 544 | func (x *classpath) FormTurbineClassPath(optName string) string { |
| 545 | return x.formJoinedClassPath(optName, " ") |
| 546 | } |
| 547 | |
| 548 | // FormRepeatedClassPath returns a list of arguments with the given optName prefixed to each element of the classpath. |
| 549 | func (x *classpath) FormRepeatedClassPath(optName string) []string { |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 550 | if x == nil || *x == nil { |
| 551 | return nil |
| 552 | } |
| 553 | flags := make([]string, len(*x)) |
| 554 | for i, v := range *x { |
Colin Cross | afbb173 | 2019-01-17 15:42:52 -0800 | [diff] [blame] | 555 | flags[i] = optName + v.String() |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | return flags |
| 559 | } |
| 560 | |
Colin Cross | 6ade34f | 2017-09-15 13:00:47 -0700 | [diff] [blame] | 561 | // Convert a classpath to an android.Paths |
| 562 | func (x *classpath) Paths() android.Paths { |
| 563 | return append(android.Paths(nil), (*x)...) |
| 564 | } |
| 565 | |
| 566 | func (x *classpath) Strings() []string { |
| 567 | if x == nil { |
| 568 | return nil |
| 569 | } |
| 570 | ret := make([]string, len(*x)) |
| 571 | for i, path := range *x { |
| 572 | ret[i] = path.String() |
| 573 | } |
| 574 | return ret |
| 575 | } |
Colin Cross | b77043e | 2019-07-16 13:57:13 -0700 | [diff] [blame] | 576 | |
| 577 | type systemModules struct { |
| 578 | dir android.Path |
| 579 | deps android.Paths |
| 580 | } |
| 581 | |
Colin Cross | bf3119e | 2019-10-28 14:25:10 -0700 | [diff] [blame] | 582 | // Returns a --system argument in the form javac expects with -source 1.9 and the list of files to |
| 583 | // depend on. If forceEmpty is true, returns --system=none if the list is empty to ensure javac |
| 584 | // does not fall back to the default system modules. |
Colin Cross | b77043e | 2019-07-16 13:57:13 -0700 | [diff] [blame] | 585 | func (x *systemModules) FormJavaSystemModulesPath(forceEmpty bool) (string, android.Paths) { |
| 586 | if x != nil { |
| 587 | return "--system=" + x.dir.String(), x.deps |
| 588 | } else if forceEmpty { |
| 589 | return "--system=none", nil |
| 590 | } else { |
| 591 | return "", nil |
| 592 | } |
| 593 | } |
Colin Cross | bf3119e | 2019-10-28 14:25:10 -0700 | [diff] [blame] | 594 | |
| 595 | // Returns a --system argument in the form turbine expects with -source 1.9 and the list of files to |
| 596 | // depend on. If forceEmpty is true, returns --bootclasspath "" if the list is empty to ensure turbine |
| 597 | // does not fall back to the default bootclasspath. |
| 598 | func (x *systemModules) FormTurbineSystemModulesPath(forceEmpty bool) (string, android.Paths) { |
| 599 | if x != nil { |
| 600 | return "--system " + x.dir.String(), x.deps |
| 601 | } else if forceEmpty { |
| 602 | return `--bootclasspath ""`, nil |
| 603 | } else { |
| 604 | return "", nil |
| 605 | } |
| 606 | } |