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