1 /* 2 * Copyright 2016 Google Inc. All Rights Reserved. 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package com.google.turbine.options; 18 19 import com.google.auto.value.AutoValue; 20 import com.google.common.collect.ImmutableList; 21 import com.google.common.collect.ImmutableSet; 22 import java.util.Optional; 23 import org.checkerframework.checker.nullness.qual.Nullable; 24 25 /** Header compilation options. */ 26 @AutoValue 27 public abstract class TurbineOptions { 28 29 /** 30 * This modes controls how a probablistic Java classpath reduction is used. For each mode except 31 * {@code NONE} a speculative compilation is performed against a subset of the original classpath. 32 * If it fails due to a missing symbol, it is retried with the original transitive classpath. 33 */ 34 public enum ReducedClasspathMode { 35 /** 36 * Bazel performs classpath reduction, and invokes turbine passing only the reduced classpath. 37 * If the compilation fails and requires fallback, turbine finishes with exit code 0 but records 38 * that the reduced classpath compilation failed in the jdeps proto. 39 */ 40 BAZEL_REDUCED, 41 /** 42 * Indicates that the reduced classpath compilation failed when Bazel previously invoked 43 * turbine, and that we are retrying with a transitive classpath. 44 */ 45 BAZEL_FALLBACK, 46 /** 47 * Turbine implements reduced classpaths locally, with in-process fallback if the compilation 48 * fails. 49 */ 50 JAVABUILDER_REDUCED, 51 /** Reduced classpaths are disabled, and a full transitive classpath is used. */ 52 NONE 53 } 54 55 /** Paths to the Java source files to compile. */ sources()56 public abstract ImmutableList<String> sources(); 57 58 /** Paths to classpath artifacts. */ classPath()59 public abstract ImmutableList<String> classPath(); 60 61 /** Paths to compilation bootclasspath artifacts. */ bootClassPath()62 public abstract ImmutableSet<String> bootClassPath(); 63 64 /** The target platform version. */ release()65 public abstract Optional<String> release(); 66 67 /** The target platform's system modules. */ system()68 public abstract Optional<String> system(); 69 70 /** The output jar. */ output()71 public abstract Optional<String> output(); 72 73 /** 74 * The output jar. 75 * 76 * @deprecated use {@link #output} instead. 77 */ 78 @Deprecated 79 @Nullable outputFile()80 public String outputFile() { 81 return output().orElse(null); 82 } 83 84 /** Paths to annotation processor artifacts. */ processorPath()85 public abstract ImmutableList<String> processorPath(); 86 87 /** Annotation processor class names. */ processors()88 public abstract ImmutableSet<String> processors(); 89 90 /** Class names of annotation processor that are built in. */ builtinProcessors()91 public abstract ImmutableSet<String> builtinProcessors(); 92 93 /** Source jars for compilation. */ sourceJars()94 public abstract ImmutableList<String> sourceJars(); 95 96 /** Output jdeps file. */ outputDeps()97 public abstract Optional<String> outputDeps(); 98 99 /** Output manifest file. */ outputManifest()100 public abstract Optional<String> outputManifest(); 101 102 /** The direct dependencies. */ directJars()103 public abstract ImmutableSet<String> directJars(); 104 105 /** The label of the target being compiled. */ targetLabel()106 public abstract Optional<String> targetLabel(); 107 108 /** 109 * If present, the name of the rule that injected an aspect that compiles this target. 110 * 111 * <p>Note that this rule will have a completely different label to {@link #targetLabel} above. 112 */ injectingRuleKind()113 public abstract Optional<String> injectingRuleKind(); 114 115 /** The .jdeps artifacts for direct dependencies. */ depsArtifacts()116 public abstract ImmutableList<String> depsArtifacts(); 117 118 /** Print usage information. */ help()119 public abstract boolean help(); 120 121 /** Additional Java compiler flags. */ javacOpts()122 public abstract ImmutableList<String> javacOpts(); 123 124 /** The reduced classpath optimization mode. */ reducedClasspathMode()125 public abstract ReducedClasspathMode reducedClasspathMode(); 126 127 /** An optional path for profiling output. */ profile()128 public abstract Optional<String> profile(); 129 130 /** An optional path for generated source output. */ gensrcOutput()131 public abstract Optional<String> gensrcOutput(); 132 133 /** An optional path for generated resource output. */ resourceOutput()134 public abstract Optional<String> resourceOutput(); 135 fullClasspathLength()136 public abstract int fullClasspathLength(); 137 reducedClasspathLength()138 public abstract int reducedClasspathLength(); 139 builder()140 public static Builder builder() { 141 return new AutoValue_TurbineOptions.Builder() 142 .setSources(ImmutableList.of()) 143 .setClassPath(ImmutableList.of()) 144 .setBootClassPath(ImmutableList.of()) 145 .setProcessorPath(ImmutableList.of()) 146 .setProcessors(ImmutableList.of()) 147 .setBuiltinProcessors(ImmutableList.of()) 148 .setSourceJars(ImmutableList.of()) 149 .setDirectJars(ImmutableList.of()) 150 .setDepsArtifacts(ImmutableList.of()) 151 .addAllJavacOpts(ImmutableList.of()) 152 .setReducedClasspathMode(ReducedClasspathMode.NONE) 153 .setHelp(false) 154 .setFullClasspathLength(0) 155 .setReducedClasspathLength(0); 156 } 157 158 /** A {@link Builder} for {@link TurbineOptions}. */ 159 @AutoValue.Builder 160 public abstract static class Builder { setOutput(String output)161 public abstract Builder setOutput(String output); 162 163 /** @deprecated use {@link #setClassPath(ImmutableList)} instead. */ 164 @Deprecated addClassPathEntries(Iterable<String> sources)165 public Builder addClassPathEntries(Iterable<String> sources) { 166 return setClassPath(ImmutableList.copyOf(sources)); 167 } 168 setClassPath(ImmutableList<String> classPath)169 public abstract Builder setClassPath(ImmutableList<String> classPath); 170 setBootClassPath(ImmutableList<String> bootClassPath)171 public abstract Builder setBootClassPath(ImmutableList<String> bootClassPath); 172 173 /** @deprecated use {@link #setBootClassPath(ImmutableList)} instead. */ 174 @Deprecated addBootClassPathEntries(Iterable<String> sources)175 public Builder addBootClassPathEntries(Iterable<String> sources) { 176 return setBootClassPath(ImmutableList.copyOf(sources)); 177 } 178 setRelease(String release)179 public abstract Builder setRelease(String release); 180 setSystem(String system)181 public abstract Builder setSystem(String system); 182 setSources(ImmutableList<String> sources)183 public abstract Builder setSources(ImmutableList<String> sources); 184 185 /** @deprecated use {@link #setSources(ImmutableList)} instead. */ 186 @Deprecated addSources(Iterable<String> sources)187 public Builder addSources(Iterable<String> sources) { 188 return setSources(ImmutableList.copyOf(sources)); 189 } 190 191 /** @deprecated use {@link #setProcessorPath(ImmutableList)} instead. */ 192 @Deprecated addProcessorPathEntries(Iterable<String> processorPath)193 public Builder addProcessorPathEntries(Iterable<String> processorPath) { 194 return setProcessorPath(ImmutableList.copyOf(processorPath)); 195 } 196 setProcessorPath(ImmutableList<String> processorPath)197 public abstract Builder setProcessorPath(ImmutableList<String> processorPath); 198 199 /** @deprecated use {@link #setProcessors(ImmutableList)} instead. */ 200 @Deprecated addProcessors(Iterable<String> processors)201 public Builder addProcessors(Iterable<String> processors) { 202 return setProcessors(ImmutableList.copyOf(processors)); 203 } 204 setProcessors(ImmutableList<String> processors)205 public abstract Builder setProcessors(ImmutableList<String> processors); 206 207 /** @deprecated use {@link #setBuiltinProcessors(ImmutableList)} instead. */ 208 @Deprecated addBuiltinProcessors(Iterable<String> builtinProcessors)209 public Builder addBuiltinProcessors(Iterable<String> builtinProcessors) { 210 return setBuiltinProcessors(ImmutableList.copyOf(builtinProcessors)); 211 } 212 setBuiltinProcessors(ImmutableList<String> builtinProcessors)213 public abstract Builder setBuiltinProcessors(ImmutableList<String> builtinProcessors); 214 setSourceJars(ImmutableList<String> sourceJars)215 public abstract Builder setSourceJars(ImmutableList<String> sourceJars); 216 setOutputDeps(String outputDeps)217 public abstract Builder setOutputDeps(String outputDeps); 218 setOutputManifest(String outputManifest)219 public abstract Builder setOutputManifest(String outputManifest); 220 setTargetLabel(String targetLabel)221 public abstract Builder setTargetLabel(String targetLabel); 222 setInjectingRuleKind(String injectingRuleKind)223 public abstract Builder setInjectingRuleKind(String injectingRuleKind); 224 225 /** @deprecated use {@link #setDepsArtifacts(ImmutableList)} instead. */ 226 @Deprecated addAllDepsArtifacts(Iterable<String> depsArtifacts)227 public Builder addAllDepsArtifacts(Iterable<String> depsArtifacts) { 228 return setDepsArtifacts(ImmutableList.copyOf(depsArtifacts)); 229 } 230 setDepsArtifacts(ImmutableList<String> depsArtifacts)231 public abstract Builder setDepsArtifacts(ImmutableList<String> depsArtifacts); 232 setHelp(boolean help)233 public abstract Builder setHelp(boolean help); 234 javacOptsBuilder()235 abstract ImmutableList.Builder<String> javacOptsBuilder(); 236 addAllJavacOpts(Iterable<String> javacOpts)237 public Builder addAllJavacOpts(Iterable<String> javacOpts) { 238 javacOptsBuilder().addAll(javacOpts); 239 return this; 240 } 241 setReducedClasspathMode(ReducedClasspathMode reducedClasspathMode)242 public abstract Builder setReducedClasspathMode(ReducedClasspathMode reducedClasspathMode); 243 244 /** @deprecated use {@link #setDirectJars(ImmutableList)} instead. */ 245 @Deprecated addDirectJars(Iterable<String> directJars)246 public Builder addDirectJars(Iterable<String> directJars) { 247 return setDirectJars(ImmutableList.copyOf(directJars)); 248 } 249 setDirectJars(ImmutableList<String> jars)250 public abstract Builder setDirectJars(ImmutableList<String> jars); 251 setProfile(String profile)252 public abstract Builder setProfile(String profile); 253 setGensrcOutput(String gensrcOutput)254 public abstract Builder setGensrcOutput(String gensrcOutput); 255 setResourceOutput(String resourceOutput)256 public abstract Builder setResourceOutput(String resourceOutput); 257 setFullClasspathLength(int fullClasspathLength)258 public abstract Builder setFullClasspathLength(int fullClasspathLength); 259 setReducedClasspathLength(int reducedClasspathLength)260 public abstract Builder setReducedClasspathLength(int reducedClasspathLength); 261 build()262 public abstract TurbineOptions build(); 263 } 264 } 265