Skip to content

Commit

Permalink
Fix precondition check for java_runtime.javahome.
Browse files Browse the repository at this point in the history
RELNOTES: None.
PiperOrigin-RevId: 155634838
  • Loading branch information
xingao267 authored and kchodorow committed May 10, 2017
1 parent 4a404de commit ed33278
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,6 @@ public final class JavaCompileAction extends SpawnAction {
*/
private final ImmutableList<String> processorNames;

/**
* The list of custom javac flags to pass to annotation processors.
*/
private final ImmutableList<String> processorFlags;

/** Set of additional Java source files to compile. */
private final ImmutableList<Artifact> sourceJars;

Expand Down Expand Up @@ -158,7 +153,6 @@ public final class JavaCompileAction extends SpawnAction {
* @param extdirInputs the compile-time extclasspath entries
* @param processorPath the classpath to search for annotation processors
* @param processorNames the annotation processors to run
* @param processorFlags custom annotation processor flags to pass to javac
* @param sourceJars jars of sources to compile
* @param sourceFiles source files to compile
* @param javacOpts the javac options for the compilation
Expand All @@ -183,7 +177,6 @@ private JavaCompileAction(
ImmutableList<Artifact> extdirInputs,
NestedSet<Artifact> processorPath,
List<String> processorNames,
List<String> processorFlags,
Collection<Artifact> sourceJars,
ImmutableSet<Artifact> sourceFiles,
List<String> javacOpts,
Expand Down Expand Up @@ -218,7 +211,6 @@ private JavaCompileAction(
this.extdirInputs = extdirInputs;
this.processorPath = processorPath;
this.processorNames = ImmutableList.copyOf(processorNames);
this.processorFlags = ImmutableList.copyOf(processorFlags);
this.sourceJars = ImmutableList.copyOf(sourceJars);
this.sourceFiles = sourceFiles;
this.javacOpts = ImmutableList.copyOf(javacOpts);
Expand Down Expand Up @@ -308,10 +300,6 @@ public List<String> getProcessorNames() {
return processorNames;
}

private List<String> getProcessorFlags() {
return processorFlags;
}

/**
* Returns the output jar artifact that gets generated by archiving the results of the Java
* compilation.
Expand Down Expand Up @@ -520,6 +508,7 @@ public static class Builder {
private PathFragment classDirectory;
private NestedSet<Artifact> processorPath = NestedSetBuilder.emptySet(Order.NAIVE_LINK_ORDER);
private final List<String> processorNames = new ArrayList<>();
/** The list of custom javac flags to pass to annotation processors. */
private final List<String> processorFlags = new ArrayList<>();
private String ruleKind;
private Label targetLabel;
Expand Down Expand Up @@ -582,8 +571,6 @@ public JavaCompileAction build() {
}

Preconditions.checkState(javaExecutable != null, owner);
Preconditions.checkState(javaExecutable.isAbsolute() ^ !javabaseInputs.isEmpty(),
javaExecutable);

ImmutableList.Builder<Artifact> outputsBuilder = ImmutableList.<Artifact>builder()
.addAll(
Expand Down Expand Up @@ -655,7 +642,6 @@ public JavaCompileAction build() {
extdirInputs,
processorPath,
processorNames,
processorFlags,
sourceJars,
sourceFiles,
internedJcopts,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import com.google.devtools.build.lib.packages.Target;
import com.google.devtools.build.lib.syntax.Type;
import com.google.devtools.build.lib.vfs.PathFragment;
import java.util.List;
import java.util.Map;
import javax.annotation.Nullable;

Expand Down Expand Up @@ -127,6 +128,14 @@ private static Jvm createFromRuntimeSuite(
PathFragment javaHomePath = defaultJavaHome(javaRuntimeLabel);
if (attributes.isAttributeValueExplicitlySpecified("java_home")) {
javaHomePath = javaHomePath.getRelative(attributes.get("java_home", Type.STRING));
List<Label> srcs = attributes.get("srcs", BuildType.LABEL_LIST);
if (!(javaHomePath.isAbsolute() ^ !srcs.isEmpty())) {
throw new InvalidConfigurationException(
String.format(
"'java_home' with an absolute path requires 'srcs' to be empty. "
+ "'java_home' was %s, 'srcs' was %s",
javaHomePath, srcs.toString()));
}
}
return new Jvm(javaHomePath, javaRuntimeLabel);
}
Expand Down

0 comments on commit ed33278

Please sign in to comment.