aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools')
-rw-r--r--src/main/java/com/google/devtools/build/lib/BUILD1
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdk.java6
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/BaseJavaCompilationHelper.java154
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationHelper.java161
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java12
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java10
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaLibraryHelper.java20
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java7
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java8
9 files changed, 182 insertions, 197 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/BUILD b/src/main/java/com/google/devtools/build/lib/BUILD
index fb2c333a58..cd602c5c63 100644
--- a/src/main/java/com/google/devtools/build/lib/BUILD
+++ b/src/main/java/com/google/devtools/build/lib/BUILD
@@ -824,7 +824,6 @@ java_library(
java_library(
name = "java-compilation",
srcs = [
- "rules/java/BaseJavaCompilationHelper.java",
"rules/java/BuildInfoPropertiesTranslator.java",
"rules/java/ClasspathConfiguredFragment.java",
"rules/java/DeployArchiveBuilder.java",
diff --git a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdk.java b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdk.java
index 6e22e81409..63434171be 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdk.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/android/AndroidSdk.java
@@ -28,7 +28,7 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.packages.AggregatingAttributeMapper;
import com.google.devtools.build.lib.rules.RuleConfiguredTargetFactory;
-import com.google.devtools.build.lib.rules.java.BaseJavaCompilationHelper;
+import com.google.devtools.build.lib.rules.java.JavaCompilationHelper;
import com.google.devtools.build.lib.rules.java.JavaConfiguration;
import com.google.devtools.build.lib.rules.java.JavaToolchainProvider;
import com.google.devtools.build.lib.syntax.Type;
@@ -93,8 +93,8 @@ public class AndroidSdk implements RuleConfiguredTargetFactory {
jack,
jill,
resourceExtractor,
- BaseJavaCompilationHelper.getBootClasspath(
- ruleContext, JavaToolchainProvider.fromRuleContext(ruleContext), ""));
+ JavaCompilationHelper.getBootClasspath(
+ JavaToolchainProvider.fromRuleContext(ruleContext)));
Artifact annotationsJar = ruleContext.getPrerequisiteArtifact("annotations_jar", Mode.HOST);
Artifact mainDexClasses = ruleContext.getPrerequisiteArtifact("main_dex_classes", Mode.HOST);
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/BaseJavaCompilationHelper.java b/src/main/java/com/google/devtools/build/lib/rules/java/BaseJavaCompilationHelper.java
deleted file mode 100644
index 510d9a0907..0000000000
--- a/src/main/java/com/google/devtools/build/lib/rules/java/BaseJavaCompilationHelper.java
+++ /dev/null
@@ -1,154 +0,0 @@
-// Copyright 2014 The Bazel Authors. All rights reserved.
-//
-// Licensed under the Apache License, Version 2.0 (the "License");
-// you may not use this file except in compliance with the License.
-// You may obtain a copy of the License at
-//
-// http://www.apache.org/licenses/LICENSE-2.0
-//
-// Unless required by applicable law or agreed to in writing, software
-// distributed under the License is distributed on an "AS IS" BASIS,
-// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-// See the License for the specific language governing permissions and
-// limitations under the License.
-
-package com.google.devtools.build.lib.rules.java;
-
-import com.google.common.collect.ImmutableList;
-import com.google.devtools.build.lib.actions.Artifact;
-import com.google.devtools.build.lib.analysis.AnalysisUtils;
-import com.google.devtools.build.lib.analysis.FileProvider;
-import com.google.devtools.build.lib.analysis.FilesToRunProvider;
-import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
-import com.google.devtools.build.lib.analysis.RuleContext;
-import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
-import com.google.devtools.build.lib.analysis.actions.SpawnAction;
-import com.google.devtools.build.lib.collect.nestedset.NestedSet;
-import com.google.devtools.build.lib.util.FileType;
-import com.google.devtools.build.lib.vfs.FileSystemUtils;
-import com.google.devtools.build.lib.vfs.PathFragment;
-
-/**
- * A helper class for compiling Java targets. This helper does not rely on the
- * presence of rule-specific attributes.
- */
-public class BaseJavaCompilationHelper {
- protected final RuleContext ruleContext;
- private final String implicitAttributesSuffix;
- protected final JavaToolchainProvider javaToolchain;
-
- public BaseJavaCompilationHelper(RuleContext ruleContext) {
- this(ruleContext, "");
- }
-
- public BaseJavaCompilationHelper(RuleContext ruleContext, String implicitAttributesSuffix) {
- this.ruleContext = ruleContext;
- this.implicitAttributesSuffix = implicitAttributesSuffix;
- this.javaToolchain =
- ruleContext.getPrerequisite(
- ":java_toolchain" + implicitAttributesSuffix, Mode.TARGET, JavaToolchainProvider.class);
- }
-
- /**
- * Returns the artifacts required to invoke {@code javahome} relative binary
- * in the action.
- */
- public NestedSet<Artifact> getHostJavabaseInputsNonStatic(RuleContext ruleContext) {
- // This must have a different name than above, because the middleman creation uses the rule's
- // configuration, although it should use the host configuration.
- return AnalysisUtils.getMiddlemanFor(ruleContext, ":host_jdk" + implicitAttributesSuffix);
- }
-
- /**
- * Returns the instrumentation jar in the given semantics.
- */
- protected Iterable<Artifact> getInstrumentationJars() {
- TransitiveInfoCollection instrumentationTarget = ruleContext.getPrerequisite(
- "$jacoco_instrumentation" + implicitAttributesSuffix, Mode.HOST);
- if (instrumentationTarget == null) {
- return ImmutableList.<Artifact>of();
- }
- return FileType.filter(
- instrumentationTarget.getProvider(FileProvider.class).getFilesToBuild(),
- JavaSemantics.JAR);
- }
-
- /**
- * Returns the javac bootclasspath artifacts from the given toolchain (if it has any) or the rule.
- */
- public static ImmutableList<Artifact> getBootClasspath(
- RuleContext ruleContext,
- JavaToolchainProvider javaToolchain,
- String implicitAttributesSuffix) {
- return ImmutableList.copyOf(javaToolchain.getBootclasspath());
- }
-
- /**
- * Returns the javac bootclasspath artifacts.
- */
- protected final ImmutableList<Artifact> getBootClasspath() {
- return getBootClasspath(ruleContext, javaToolchain, implicitAttributesSuffix);
- }
-
- /**
- * Returns the extdir artifacts.
- */
- protected final ImmutableList<Artifact> getExtdirInputs() {
- return ImmutableList.copyOf(javaToolchain.getExtclasspath());
- }
-
- private Artifact getIjarArtifact(Artifact jar, boolean addPrefix) {
- if (addPrefix) {
- PathFragment ruleBase = ruleContext.getUniqueDirectory("_ijar");
- PathFragment artifactDirFragment = jar.getRootRelativePath().getParentDirectory();
- String ijarBasename = FileSystemUtils.removeExtension(jar.getFilename()) + "-ijar.jar";
- return ruleContext.getDerivedArtifact(
- ruleBase.getRelative(artifactDirFragment).getRelative(ijarBasename),
- ruleContext.getConfiguration().getGenfilesDirectory(
- ruleContext.getRule().getRepository()));
- } else {
- return derivedArtifact(jar, "", "-ijar.jar");
- }
- }
-
- /**
- * Creates the Action that creates ijars from Jar files.
- *
- * @param inputJar the Jar to create the ijar for
- * @param addPrefix whether to prefix the path of the generated ijar with the package and
- * name of the current rule
- * @return the Artifact to create with the Action
- */
- protected Artifact createIjarAction(Artifact inputJar, boolean addPrefix) {
- Artifact interfaceJar = getIjarArtifact(inputJar, addPrefix);
- FilesToRunProvider ijarTarget = javaToolchain.getIjar();
- if (!ruleContext.hasErrors()) {
- ruleContext.registerAction(new SpawnAction.Builder()
- .addInput(inputJar)
- .addOutput(interfaceJar)
- .setExecutable(ijarTarget)
- // On Windows, ijar.exe needs msys-2.0.dll and zlib1.dll in PATH.
- // Use default shell environment so that those can be found.
- // TODO(dslomov): revisit this. If ijar is not msys-dependent, this is not needed.
- .useDefaultShellEnvironment()
- .addArgument(inputJar.getExecPathString())
- .addArgument(interfaceJar.getExecPathString())
- .setProgressMessage("Extracting interface " + ruleContext.getLabel())
- .setMnemonic("JavaIjar")
- .build(ruleContext));
- }
- return interfaceJar;
- }
-
- /**
- * Creates a derived artifact from the given artifact by adding the given
- * prefix and removing the extension and replacing it by the given suffix.
- * The new artifact will have the same root as the given one.
- */
- private Artifact derivedArtifact(Artifact artifact, String prefix, String suffix) {
- PathFragment path = artifact.getRootRelativePath();
- String basename = FileSystemUtils.removeExtension(path.getBaseName()) + suffix;
- path = path.replaceName(prefix + basename);
- return ruleContext.getDerivedArtifact(path, artifact.getRoot());
- }
-}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationHelper.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationHelper.java
index fec64a367a..9ae2dbee79 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationHelper.java
@@ -23,6 +23,8 @@ import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.ParameterFile.ParameterFileType;
import com.google.devtools.build.lib.analysis.AnalysisEnvironment;
import com.google.devtools.build.lib.analysis.AnalysisUtils;
+import com.google.devtools.build.lib.analysis.FileProvider;
+import com.google.devtools.build.lib.analysis.FilesToRunProvider;
import com.google.devtools.build.lib.analysis.RuleConfiguredTarget.Mode;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
@@ -34,6 +36,7 @@ import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
import com.google.devtools.build.lib.rules.java.JavaConfiguration.JavaClasspathMode;
import com.google.devtools.build.lib.rules.test.InstrumentedFilesCollector;
+import com.google.devtools.build.lib.util.FileType;
import com.google.devtools.build.lib.util.Preconditions;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
import com.google.devtools.build.lib.vfs.PathFragment;
@@ -50,8 +53,12 @@ import javax.annotation.Nullable;
* <p>
* Also supports the creation of resource and source only Jars.
*/
-public final class JavaCompilationHelper extends BaseJavaCompilationHelper {
+public final class JavaCompilationHelper {
+ private final RuleContext ruleContext;
+ private final JavaToolchainProvider javaToolchain;
+ private final NestedSet<Artifact> hostJavabase;
+ private final Iterable<Artifact> jacocoInstrumentation;
private JavaTargetAttributes.Builder attributes;
private JavaTargetAttributes builtAttributes;
private final ImmutableList<String> customJavacOpts;
@@ -59,13 +66,18 @@ public final class JavaCompilationHelper extends BaseJavaCompilationHelper {
private final List<Artifact> translations = new ArrayList<>();
private boolean translationsFrozen;
private final JavaSemantics semantics;
- private final String implicitAttributesSuffix;
+
+ private static final String DEFAULT_ATTRIBUTES_SUFFIX = "";
public JavaCompilationHelper(RuleContext ruleContext, JavaSemantics semantics,
ImmutableList<String> javacOpts, JavaTargetAttributes.Builder attributes,
- String implicitAttributesSuffix) {
- super(ruleContext, implicitAttributesSuffix);
- this.implicitAttributesSuffix = implicitAttributesSuffix;
+ JavaToolchainProvider javaToolchainProvider,
+ NestedSet<Artifact> hostJavabase,
+ Iterable<Artifact> jacocoInstrumentation) {
+ this.ruleContext = ruleContext;
+ this.javaToolchain = javaToolchainProvider;
+ this.hostJavabase = hostJavabase;
+ this.jacocoInstrumentation = jacocoInstrumentation;
this.attributes = attributes;
this.customJavacOpts = javacOpts;
this.customJavacJvmOpts = javaToolchain.getJvmOptions();
@@ -74,7 +86,10 @@ public final class JavaCompilationHelper extends BaseJavaCompilationHelper {
public JavaCompilationHelper(RuleContext ruleContext, JavaSemantics semantics,
ImmutableList<String> javacOpts, JavaTargetAttributes.Builder attributes) {
- this(ruleContext, semantics, javacOpts, attributes, "");
+ this(ruleContext, semantics, javacOpts, attributes,
+ getJavaToolchainProvider(ruleContext),
+ getHostJavabaseInputsNonStatic(ruleContext),
+ getInstrumentationJars(ruleContext));
}
public JavaCompilationHelper(RuleContext ruleContext, JavaSemantics semantics,
@@ -138,7 +153,7 @@ public final class JavaCompilationHelper extends BaseJavaCompilationHelper {
builder.setGensrcOutputJar(gensrcOutputJar);
builder.setOutputDepsProto(outputDepsProto);
builder.setMetadata(outputMetadata);
- builder.setInstrumentationJars(getInstrumentationJars());
+ builder.setInstrumentationJars(jacocoInstrumentation);
builder.addSourceFiles(attributes.getSourceFiles());
builder.addSourceJars(attributes.getSourceJars());
builder.setJavacOpts(customJavacOpts);
@@ -267,7 +282,7 @@ public final class JavaCompilationHelper extends BaseJavaCompilationHelper {
JavaTargetAttributes attributes = getAttributes();
JavaHeaderCompileAction.Builder builder =
- new JavaHeaderCompileAction.Builder(getRuleContext(), implicitAttributesSuffix);
+ new JavaHeaderCompileAction.Builder(getRuleContext());
builder.addSourceFiles(attributes.getSourceFiles());
builder.addSourceJars(attributes.getSourceJars());
builder.setClasspathEntries(attributes.getCompileTimeClassPath());
@@ -287,9 +302,9 @@ public final class JavaCompilationHelper extends BaseJavaCompilationHelper {
builder.setDirectJars(attributes.getDirectJars());
builder.setRuleKind(attributes.getRuleKind());
builder.setTargetLabel(attributes.getTargetLabel());
- builder.setJavaBaseInputs(getHostJavabaseInputsNonStatic(ruleContext));
+ builder.setJavaBaseInputs(hostJavabase);
builder.setJavacJar(javaToolchain.getJavac());
- builder.build();
+ builder.build(javaToolchain);
artifactBuilder.setCompileTimeDependencies(headerDeps);
return headerJar;
@@ -451,7 +466,7 @@ public final class JavaCompilationHelper extends BaseJavaCompilationHelper {
JavaCompileAction.Builder builder = new JavaCompileAction.Builder(ruleContext, semantics);
builder.setJavaExecutable(
ruleContext.getHostConfiguration().getFragment(Jvm.class).getJavaExecutable());
- builder.setJavaBaseInputs(getHostJavabaseInputsNonStatic(ruleContext));
+ builder.setJavaBaseInputs(hostJavabase);
builder.setTargetLabel(ruleContext.getLabel());
return builder;
}
@@ -518,7 +533,7 @@ public final class JavaCompilationHelper extends BaseJavaCompilationHelper {
if (shouldUseHeaderCompilation()) {
jar = createHeaderCompilationAction(runtimeJar, builder);
} else if (getJavaConfiguration().getUseIjars()) {
- jar = createIjarAction(runtimeJar, false);
+ jar = createIjarAction(ruleContext, javaToolchain, runtimeJar, false);
} else {
jar = runtimeJar;
}
@@ -631,4 +646,126 @@ public final class JavaCompilationHelper extends BaseJavaCompilationHelper {
translationsFrozen = true;
return ImmutableList.copyOf(translations);
}
+
+ public static JavaToolchainProvider getJavaToolchainProvider(
+ RuleContext ruleContext, String implicitAttributesSuffix) {
+ return ruleContext.getPrerequisite(
+ ":java_toolchain" + implicitAttributesSuffix, Mode.TARGET, JavaToolchainProvider.class);
+ }
+
+ public static JavaToolchainProvider getJavaToolchainProvider(RuleContext ruleContext) {
+ return getJavaToolchainProvider(ruleContext, DEFAULT_ATTRIBUTES_SUFFIX);
+ }
+
+ /**
+ * Returns the artifacts required to invoke {@code javahome} relative binary
+ * in the action.
+ */
+ public static NestedSet<Artifact> getHostJavabaseInputsNonStatic(
+ RuleContext ruleContext, String implicitAttributesSuffix) {
+ // This must have a different name than above, because the middleman creation uses the rule's
+ // configuration, although it should use the host configuration.
+ return AnalysisUtils.getMiddlemanFor(ruleContext, ":host_jdk" + implicitAttributesSuffix);
+ }
+
+ public static NestedSet<Artifact> getHostJavabaseInputsNonStatic(RuleContext ruleContext) {
+ return getHostJavabaseInputsNonStatic(ruleContext, DEFAULT_ATTRIBUTES_SUFFIX);
+ }
+
+ /**
+ * Returns the instrumentation jar in the given semantics.
+ */
+ public static Iterable<Artifact> getInstrumentationJars(
+ RuleContext ruleContext, String implicitAttributesSuffix) {
+ TransitiveInfoCollection instrumentationTarget = ruleContext.getPrerequisite(
+ "$jacoco_instrumentation" + implicitAttributesSuffix, Mode.HOST);
+ if (instrumentationTarget == null) {
+ return ImmutableList.<Artifact>of();
+ }
+ return FileType.filter(
+ instrumentationTarget.getProvider(FileProvider.class).getFilesToBuild(),
+ JavaSemantics.JAR);
+ }
+
+ public static Iterable<Artifact> getInstrumentationJars(RuleContext ruleContext) {
+ return getInstrumentationJars(ruleContext, DEFAULT_ATTRIBUTES_SUFFIX);
+ }
+
+ /**
+ * Returns the javac bootclasspath artifacts from the given toolchain (if it has any) or the rule.
+ */
+ public static ImmutableList<Artifact> getBootClasspath(JavaToolchainProvider javaToolchain) {
+ return ImmutableList.copyOf(javaToolchain.getBootclasspath());
+ }
+
+ private ImmutableList<Artifact> getBootClasspath() {
+ return ImmutableList.copyOf(javaToolchain.getBootclasspath());
+ }
+
+ /**
+ * Returns the extdir artifacts.
+ */
+ private final ImmutableList<Artifact> getExtdirInputs() {
+ return ImmutableList.copyOf(javaToolchain.getExtclasspath());
+ }
+
+ /**
+ * Creates the Action that creates ijars from Jar files.
+ *
+ * @param inputJar the Jar to create the ijar for
+ * @param addPrefix whether to prefix the path of the generated ijar with the package and
+ * name of the current rule
+ * @return the Artifact to create with the Action
+ */
+ protected static Artifact createIjarAction(
+ RuleContext ruleContext,
+ JavaToolchainProvider javaToolchain,
+ Artifact inputJar, boolean addPrefix) {
+ Artifact interfaceJar = getIjarArtifact(ruleContext, inputJar, addPrefix);
+ FilesToRunProvider ijarTarget = javaToolchain.getIjar();
+ if (!ruleContext.hasErrors()) {
+ ruleContext.registerAction(new SpawnAction.Builder()
+ .addInput(inputJar)
+ .addOutput(interfaceJar)
+ .setExecutable(ijarTarget)
+ // On Windows, ijar.exe needs msys-2.0.dll and zlib1.dll in PATH.
+ // Use default shell environment so that those can be found.
+ // TODO(dslomov): revisit this. If ijar is not msys-dependent, this is not needed.
+ .useDefaultShellEnvironment()
+ .addArgument(inputJar.getExecPathString())
+ .addArgument(interfaceJar.getExecPathString())
+ .setProgressMessage("Extracting interface " + ruleContext.getLabel())
+ .setMnemonic("JavaIjar")
+ .build(ruleContext));
+ }
+ return interfaceJar;
+ }
+
+ private static Artifact getIjarArtifact(
+ RuleContext ruleContext, Artifact jar, boolean addPrefix) {
+ if (addPrefix) {
+ PathFragment ruleBase = ruleContext.getUniqueDirectory("_ijar");
+ PathFragment artifactDirFragment = jar.getRootRelativePath().getParentDirectory();
+ String ijarBasename = FileSystemUtils.removeExtension(jar.getFilename()) + "-ijar.jar";
+ return ruleContext.getDerivedArtifact(
+ ruleBase.getRelative(artifactDirFragment).getRelative(ijarBasename),
+ ruleContext.getConfiguration().getGenfilesDirectory(
+ ruleContext.getRule().getRepository()));
+ } else {
+ return derivedArtifact(ruleContext, jar, "", "-ijar.jar");
+ }
+ }
+
+ /**
+ * Creates a derived artifact from the given artifact by adding the given
+ * prefix and removing the extension and replacing it by the given suffix.
+ * The new artifact will have the same root as the given one.
+ */
+ private static Artifact derivedArtifact(
+ RuleContext ruleContext, Artifact artifact, String prefix, String suffix) {
+ PathFragment path = artifact.getRootRelativePath();
+ String basename = FileSystemUtils.removeExtension(path.getBaseName()) + suffix;
+ path = path.replaceName(prefix + basename);
+ return ruleContext.getDerivedArtifact(path, artifact.getRoot());
+ }
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java
index 19e88ef76f..b9b08b32b6 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaHeaderCompileAction.java
@@ -27,7 +27,6 @@ import com.google.devtools.build.lib.actions.ActionOwner;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.ParameterFile;
import com.google.devtools.build.lib.actions.ResourceSet;
-import com.google.devtools.build.lib.analysis.RuleConfiguredTarget;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.actions.CommandLine;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
@@ -95,7 +94,6 @@ public class JavaHeaderCompileAction extends SpawnAction {
public static class Builder {
private final RuleContext ruleContext;
- private final String implicitAttributesSuffix;
private Artifact outputJar;
@Nullable private Artifact outputDepsProto;
@@ -117,9 +115,8 @@ public class JavaHeaderCompileAction extends SpawnAction {
private NestedSet<Artifact> javabaseInputs;
private Artifact javacJar;
- public Builder(RuleContext ruleContext, String implicitAttributesSuffix) {
+ public Builder(RuleContext ruleContext) {
this.ruleContext = ruleContext;
- this.implicitAttributesSuffix = implicitAttributesSuffix;
}
/** Sets the output jdeps file. */
@@ -259,7 +256,7 @@ public class JavaHeaderCompileAction extends SpawnAction {
return this;
}
/** Builds and registers the {@link JavaHeaderCompileAction} for a header compilation. */
- public void build() {
+ public void build(JavaToolchainProvider javaToolchain) {
checkNotNull(outputDepsProto, "outputDepsProto must not be null");
checkNotNull(sourceFiles, "sourceFiles must not be null");
checkNotNull(sourceJars, "sourceJars must not be null");
@@ -281,11 +278,6 @@ public class JavaHeaderCompileAction extends SpawnAction {
directJars = NestedSetBuilder.emptySet(Order.NAIVE_LINK_ORDER);
compileTimeDependencyArtifacts.clear();
}
- JavaToolchainProvider javaToolchain =
- ruleContext.getPrerequisite(
- ":java_toolchain" + implicitAttributesSuffix,
- RuleConfiguredTarget.Mode.TARGET,
- JavaToolchainProvider.class);
List<String> jvmArgs =
ImmutableList.<String>builder()
.add("-Xverify:none")
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java
index 5687571745..df7cdf8c33 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaImport.java
@@ -69,11 +69,10 @@ public class JavaImport implements RuleConfiguredTargetFactory {
semantics.checkRule(ruleContext, common);
// No need for javac options - no compilation happening here.
- BaseJavaCompilationHelper helper = new BaseJavaCompilationHelper(ruleContext);
ImmutableBiMap.Builder<Artifact, Artifact> compilationToRuntimeJarMapBuilder =
ImmutableBiMap.builder();
ImmutableList<Artifact> interfaceJars =
- processWithIjar(jars, helper, compilationToRuntimeJarMapBuilder);
+ processWithIjar(jars, ruleContext, compilationToRuntimeJarMapBuilder);
JavaCompilationArtifacts javaArtifacts = collectJavaArtifacts(jars, interfaceJars);
common.setJavaCompilationArtifacts(javaArtifacts);
@@ -221,11 +220,14 @@ public class JavaImport implements RuleConfiguredTargetFactory {
}
private ImmutableList<Artifact> processWithIjar(ImmutableList<Artifact> jars,
- BaseJavaCompilationHelper helper,
+ RuleContext ruleContext,
ImmutableMap.Builder<Artifact, Artifact> compilationToRuntimeJarMap) {
ImmutableList.Builder<Artifact> interfaceJarsBuilder = ImmutableList.builder();
for (Artifact jar : jars) {
- Artifact ijar = helper.createIjarAction(jar, true);
+ Artifact ijar = JavaCompilationHelper.createIjarAction(
+ ruleContext,
+ JavaCompilationHelper.getJavaToolchainProvider(ruleContext),
+ jar, true);
interfaceJarsBuilder.add(ijar);
compilationToRuntimeJarMap.put(ijar, jar);
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibraryHelper.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibraryHelper.java
index 17c1846a97..7f619c2e78 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibraryHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaLibraryHelper.java
@@ -39,10 +39,7 @@ import java.util.List;
* Java compiler.
*/
public final class JavaLibraryHelper {
- private static final String DEFAULT_SUFFIX_IS_EMPTY_STRING = "";
-
private final RuleContext ruleContext;
- private final String implicitAttributesSuffix;
private Artifact output;
private final List<Artifact> sourceJars = new ArrayList<>();
@@ -57,14 +54,9 @@ public final class JavaLibraryHelper {
private JavaClasspathMode classpathMode = JavaClasspathMode.OFF;
public JavaLibraryHelper(RuleContext ruleContext) {
- this(ruleContext, DEFAULT_SUFFIX_IS_EMPTY_STRING);
- }
-
- public JavaLibraryHelper(RuleContext ruleContext, String implicitAttributesSuffix) {
this.ruleContext = ruleContext;
ruleContext.getConfiguration();
this.classpathMode = ruleContext.getFragment(JavaConfiguration.class).getReduceJavaClasspath();
- this.implicitAttributesSuffix = implicitAttributesSuffix;
}
/**
@@ -131,7 +123,11 @@ public final class JavaLibraryHelper {
/**
* Creates the compile actions.
*/
- public JavaCompilationArgs build(JavaSemantics semantics) {
+ public JavaCompilationArgs build(
+ JavaSemantics semantics,
+ JavaToolchainProvider javaToolchainProvider,
+ NestedSet<Artifact> hostJavabase,
+ Iterable<Artifact> jacocoInstrumental) {
Preconditions.checkState(output != null, "must have an output file; use setOutput()");
JavaTargetAttributes.Builder attributes = new JavaTargetAttributes.Builder(semantics);
attributes.addSourceJars(sourceJars);
@@ -147,8 +143,10 @@ public final class JavaLibraryHelper {
JavaCompilationArtifacts.Builder artifactsBuilder = new JavaCompilationArtifacts.Builder();
JavaCompilationHelper helper =
- new JavaCompilationHelper(
- ruleContext, semantics, javacOpts, attributes, implicitAttributesSuffix);
+ new JavaCompilationHelper(ruleContext, semantics, javacOpts, attributes,
+ javaToolchainProvider,
+ hostJavabase,
+ jacocoInstrumental);
Artifact outputDepsProto = helper.createOutputDepsProtoArtifact(output, artifactsBuilder);
helper.createCompileAction(
output,
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java
index 4e0c5c853c..536a555697 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java
@@ -48,6 +48,7 @@ import com.google.devtools.build.lib.packages.NativeAspectClass;
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.rules.java.JavaCompilationArgs;
import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider;
+import com.google.devtools.build.lib.rules.java.JavaCompilationHelper;
import com.google.devtools.build.lib.rules.java.JavaConfiguration;
import com.google.devtools.build.lib.rules.java.JavaLibraryHelper;
import com.google.devtools.build.lib.rules.java.JavaSemantics;
@@ -220,7 +221,11 @@ public class JavaLiteProtoAspect extends NativeAspectClass implements Configured
helper.addDep(runtime.getProvider(JavaCompilationArgsProvider.class));
}
helper.setCompilationStrictDepsMode(StrictDepsMode.OFF);
- JavaCompilationArgs artifacts = helper.build(javaSemantics);
+ JavaCompilationArgs artifacts = helper.build(
+ javaSemantics,
+ JavaCompilationHelper.getJavaToolchainProvider(ruleContext),
+ JavaCompilationHelper.getHostJavabaseInputsNonStatic(ruleContext),
+ JavaCompilationHelper.getInstrumentationJars(ruleContext));
return helper.buildCompilationArgsProvider(artifacts, true /* isReportedAsStrict */);
}
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java
index 02308f7391..c00d924648 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java
@@ -50,6 +50,7 @@ import com.google.devtools.build.lib.packages.AttributeMap;
import com.google.devtools.build.lib.packages.NativeAspectClass;
import com.google.devtools.build.lib.packages.Rule;
import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider;
+import com.google.devtools.build.lib.rules.java.JavaCompilationHelper;
import com.google.devtools.build.lib.rules.java.JavaConfiguration;
import com.google.devtools.build.lib.rules.java.JavaLibraryHelper;
import com.google.devtools.build.lib.rules.java.JavaSemantics;
@@ -342,7 +343,12 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe
rpcSupport.mutateJavaCompileAction(ruleContext, helper);
return helper.buildCompilationArgsProvider(
- helper.build(javaSemantics), true /* isReportedAsStrict */);
+ helper.build(
+ javaSemantics,
+ JavaCompilationHelper.getJavaToolchainProvider(ruleContext),
+ JavaCompilationHelper.getHostJavabaseInputsNonStatic(ruleContext),
+ JavaCompilationHelper.getInstrumentationJars(ruleContext)),
+ true /* isReportedAsStrict */);
}
private ProtoLangToolchainProvider getProtoToolchainProvider() {