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 com.google.errorprone.annotations.CanIgnoreReturnValue; 23 import java.util.Optional; 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 language version. */ languageVersion()65 public abstract LanguageVersion languageVersion(); 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 /** Paths to annotation processor artifacts. */ processorPath()74 public abstract ImmutableList<String> processorPath(); 75 76 /** Annotation processor class names. */ processors()77 public abstract ImmutableSet<String> processors(); 78 79 /** Class names of annotation processor that are built in. */ builtinProcessors()80 public abstract ImmutableSet<String> builtinProcessors(); 81 82 /** Source jars for compilation. */ sourceJars()83 public abstract ImmutableList<String> sourceJars(); 84 85 /** Output jdeps file. */ outputDeps()86 public abstract Optional<String> outputDeps(); 87 88 /** Output manifest file. */ outputManifest()89 public abstract Optional<String> outputManifest(); 90 91 /** The direct dependencies. */ directJars()92 public abstract ImmutableSet<String> directJars(); 93 94 /** The label of the target being compiled. */ targetLabel()95 public abstract Optional<String> targetLabel(); 96 97 /** 98 * If present, the name of the rule that injected an aspect that compiles this target. 99 * 100 * <p>Note that this rule will have a completely different label to {@link #targetLabel} above. 101 */ injectingRuleKind()102 public abstract Optional<String> injectingRuleKind(); 103 104 /** The .jdeps artifacts for direct dependencies. */ depsArtifacts()105 public abstract ImmutableList<String> depsArtifacts(); 106 107 /** Print usage information. */ help()108 public abstract boolean help(); 109 110 /** Additional Java compiler flags. */ javacOpts()111 public abstract ImmutableList<String> javacOpts(); 112 113 /** The reduced classpath optimization mode. */ reducedClasspathMode()114 public abstract ReducedClasspathMode reducedClasspathMode(); 115 116 /** An optional path for profiling output. */ profile()117 public abstract Optional<String> profile(); 118 119 /** An optional path for generated source output. */ gensrcOutput()120 public abstract Optional<String> gensrcOutput(); 121 122 /** An optional path for generated resource output. */ resourceOutput()123 public abstract Optional<String> resourceOutput(); 124 fullClasspathLength()125 public abstract int fullClasspathLength(); 126 reducedClasspathLength()127 public abstract int reducedClasspathLength(); 128 builder()129 public static Builder builder() { 130 return new AutoValue_TurbineOptions.Builder() 131 .setSources(ImmutableList.of()) 132 .setClassPath(ImmutableList.of()) 133 .setBootClassPath(ImmutableList.of()) 134 .setProcessorPath(ImmutableList.of()) 135 .setProcessors(ImmutableList.of()) 136 .setBuiltinProcessors(ImmutableList.of()) 137 .setSourceJars(ImmutableList.of()) 138 .setDirectJars(ImmutableList.of()) 139 .setDepsArtifacts(ImmutableList.of()) 140 .addAllJavacOpts(ImmutableList.of()) 141 .setLanguageVersion(LanguageVersion.createDefault()) 142 .setReducedClasspathMode(ReducedClasspathMode.NONE) 143 .setHelp(false) 144 .setFullClasspathLength(0) 145 .setReducedClasspathLength(0); 146 } 147 148 /** A {@link Builder} for {@link TurbineOptions}. */ 149 @AutoValue.Builder 150 public abstract static class Builder { setOutput(String output)151 public abstract Builder setOutput(String output); 152 setClassPath(ImmutableList<String> classPath)153 public abstract Builder setClassPath(ImmutableList<String> classPath); 154 setBootClassPath(ImmutableList<String> bootClassPath)155 public abstract Builder setBootClassPath(ImmutableList<String> bootClassPath); 156 setLanguageVersion(LanguageVersion languageVersion)157 public abstract Builder setLanguageVersion(LanguageVersion languageVersion); 158 setSystem(String system)159 public abstract Builder setSystem(String system); 160 setSources(ImmutableList<String> sources)161 public abstract Builder setSources(ImmutableList<String> sources); 162 setProcessorPath(ImmutableList<String> processorPath)163 public abstract Builder setProcessorPath(ImmutableList<String> processorPath); 164 setProcessors(ImmutableList<String> processors)165 public abstract Builder setProcessors(ImmutableList<String> processors); 166 setBuiltinProcessors(ImmutableList<String> builtinProcessors)167 public abstract Builder setBuiltinProcessors(ImmutableList<String> builtinProcessors); 168 setSourceJars(ImmutableList<String> sourceJars)169 public abstract Builder setSourceJars(ImmutableList<String> sourceJars); 170 setOutputDeps(String outputDeps)171 public abstract Builder setOutputDeps(String outputDeps); 172 setOutputManifest(String outputManifest)173 public abstract Builder setOutputManifest(String outputManifest); 174 setTargetLabel(String targetLabel)175 public abstract Builder setTargetLabel(String targetLabel); 176 setInjectingRuleKind(String injectingRuleKind)177 public abstract Builder setInjectingRuleKind(String injectingRuleKind); 178 setDepsArtifacts(ImmutableList<String> depsArtifacts)179 public abstract Builder setDepsArtifacts(ImmutableList<String> depsArtifacts); 180 setHelp(boolean help)181 public abstract Builder setHelp(boolean help); 182 javacOptsBuilder()183 abstract ImmutableList.Builder<String> javacOptsBuilder(); 184 185 @CanIgnoreReturnValue addAllJavacOpts(Iterable<String> javacOpts)186 public Builder addAllJavacOpts(Iterable<String> javacOpts) { 187 javacOptsBuilder().addAll(javacOpts); 188 return this; 189 } 190 setReducedClasspathMode(ReducedClasspathMode reducedClasspathMode)191 public abstract Builder setReducedClasspathMode(ReducedClasspathMode reducedClasspathMode); 192 setDirectJars(ImmutableList<String> jars)193 public abstract Builder setDirectJars(ImmutableList<String> jars); 194 setProfile(String profile)195 public abstract Builder setProfile(String profile); 196 setGensrcOutput(String gensrcOutput)197 public abstract Builder setGensrcOutput(String gensrcOutput); 198 setResourceOutput(String resourceOutput)199 public abstract Builder setResourceOutput(String resourceOutput); 200 setFullClasspathLength(int fullClasspathLength)201 public abstract Builder setFullClasspathLength(int fullClasspathLength); 202 setReducedClasspathLength(int reducedClasspathLength)203 public abstract Builder setReducedClasspathLength(int reducedClasspathLength); 204 build()205 public abstract TurbineOptions build(); 206 } 207 } 208