aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java18
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaCompilationHelper.java21
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaHelper.java14
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaInfo.java20
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaLibraryHelper.java49
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaSkylarkCommon.java53
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/SingleJarActionBuilder.java73
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaLiteProtoAspect.java15
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/proto/JavaProtoAspect.java6
9 files changed, 214 insertions, 55 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java
index dbcccb88d0..10610aa4cf 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaCommon.java
@@ -473,6 +473,24 @@ public class JavaCommon {
: ruleContext.getHostConfiguration().getFragment(Jvm.class).getJavaExecutable();
}
+ /**
+ * Returns the host java executable.
+ *
+ * <p>The method looks for the executable in the following
+ * locations (in the specified order) and returns it immediately after it's found:
+ * <ol>
+ * <li> The JavaRuntimeInfo in the given hostJavabase target
+ * <li> The JVM fragment of the host configuration, retrieved from the given rule context
+ * </ol>
+ */
+ public static PathFragment getHostJavaExecutable(
+ RuleContext ruleContext, TransitiveInfoCollection hostJavabase) {
+ JavaRuntimeInfo javaRuntime = hostJavabase.get(JavaRuntimeInfo.PROVIDER);
+ return javaRuntime != null
+ ? javaRuntime.javaBinaryExecPath()
+ : ruleContext.getHostConfiguration().getFragment(Jvm.class).getJavaExecutable();
+ }
+
public static PathFragment getJavaExecutable(RuleContext ruleContext) {
JavaRuntimeInfo javaRuntime = JavaHelper.getJavaRuntime(ruleContext);
return javaRuntime != null
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 d0fd5b862b..64140170cf 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
@@ -582,7 +582,28 @@ public final class JavaCompilationHelper {
* @param outputJar the Artifact to create with the Action
* @param gensrcJar the generated sources jar Artifact that should be included with the
* sources in the output Artifact. May be null.
+ * @param javaToolchainProvider is used by SingleJarActionBuilder to retrieve jvm options
+ * @param hostJavabaseInputs Artifacts required to invoke java executable in the SingleJar action
+ * @param hostJavaExecutable the jar executable of the SingleJar action
*/
+ public void createSourceJarAction(
+ Artifact outputJar,
+ @Nullable Artifact gensrcJar,
+ JavaToolchainProvider javaToolchainProvider,
+ NestedSet<Artifact> hostJavabaseInputs,
+ PathFragment hostJavaExecutable) {
+ JavaTargetAttributes attributes = getAttributes();
+ NestedSetBuilder<Artifact> resourceJars = NestedSetBuilder.stableOrder();
+ resourceJars.addAll(attributes.getSourceJars());
+ if (gensrcJar != null) {
+ resourceJars.add(gensrcJar);
+ }
+ SingleJarActionBuilder.createSourceJarAction(
+ ruleContext, semantics, attributes.getSourceFiles(),
+ resourceJars.build(), outputJar, javaToolchainProvider,
+ hostJavabaseInputs, hostJavaExecutable);
+ }
+
public void createSourceJarAction(Artifact outputJar, @Nullable Artifact gensrcJar) {
JavaTargetAttributes attributes = getAttributes();
NestedSetBuilder<Artifact> resourceJars = NestedSetBuilder.stableOrder();
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaHelper.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaHelper.java
index 91dbb09897..d9a2bc456e 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaHelper.java
@@ -137,6 +137,20 @@ public abstract class JavaHelper {
return rootRelativePath.relativeTo(prefix);
}
+ /** Returns the configured target found under the {@code :host_jdk} attribute of a given rule. */
+ public static TransitiveInfoCollection getHostJavabaseTarget(RuleContext ruleContext) {
+ return getHostJavabaseTarget(ruleContext, "");
+ }
+
+ /**
+ * Returns the configured target found under the {@code :host_jdk + implicitAttributesSuffix}
+ * attribute of a given rule.
+ * */
+ public static TransitiveInfoCollection getHostJavabaseTarget(
+ RuleContext ruleContext, String implicitAttributesSuffix) {
+ return ruleContext.getPrerequisite(":host_jdk" + implicitAttributesSuffix, Mode.HOST);
+ }
+
/** Returns the artifacts required to invoke {@code javahome} relative binary in the action. */
public static NestedSet<Artifact> getHostJavabaseInputs(RuleContext ruleContext) {
return getHostJavabaseInputs(ruleContext, "");
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfo.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfo.java
index 9384d0cbdf..d93f4ba52c 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfo.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfo.java
@@ -22,6 +22,9 @@ import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.TransitiveInfoProvider;
import com.google.devtools.build.lib.analysis.TransitiveInfoProviderMap;
import com.google.devtools.build.lib.analysis.TransitiveInfoProviderMapBuilder;
+import com.google.devtools.build.lib.collect.nestedset.NestedSet;
+import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
+import com.google.devtools.build.lib.collect.nestedset.Order;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
import com.google.devtools.build.lib.packages.NativeInfo;
import com.google.devtools.build.lib.packages.NativeProvider;
@@ -31,7 +34,6 @@ import com.google.devtools.build.lib.skylarkinterface.SkylarkModuleCategory;
import com.google.devtools.build.lib.syntax.SkylarkList;
import com.google.devtools.build.lib.syntax.SkylarkNestedSet;
import java.util.ArrayList;
-import java.util.LinkedList;
import java.util.List;
import javax.annotation.Nullable;
@@ -119,7 +121,7 @@ public final class JavaInfo extends NativeInfo {
*/
public static <C extends TransitiveInfoProvider> List<C> fetchProvidersFromList(
Iterable<JavaInfo> javaProviders, Class<C> providersClass) {
- List<C> fetchedProviders = new LinkedList<>();
+ List<C> fetchedProviders = new ArrayList<>();
for (JavaInfo javaInfo : javaProviders) {
C provider = javaInfo.getProvider(providersClass);
if (provider != null) {
@@ -272,6 +274,20 @@ public final class JavaInfo extends NativeInfo {
}
@SkylarkCallable(
+ name = "transitive_source_jars",
+ doc = "Returns the Jars containing Java source files for the target and all of its "
+ + "transitive dependencies.",
+ structField = true
+ )
+ public NestedSet<Artifact> getTransitiveSourceJars() {
+ JavaSourceJarsProvider sourceJarsProvider = getProvider(JavaSourceJarsProvider.class);
+ if (sourceJarsProvider == null) {
+ return NestedSetBuilder.emptySet(Order.STABLE_ORDER);
+ }
+ return sourceJarsProvider.getTransitiveSourceJars();
+ }
+
+ @SkylarkCallable(
name = "outputs",
doc = "Returns information about outputs of this Java target.",
structField = true,
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 941e7b6e98..4e36c4d1e8 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
@@ -22,7 +22,9 @@ import com.google.common.base.Preconditions;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.Artifact;
+import com.google.devtools.build.lib.analysis.MiddlemanProvider;
import com.google.devtools.build.lib.analysis.RuleContext;
+import com.google.devtools.build.lib.analysis.TransitiveInfoCollection;
import com.google.devtools.build.lib.analysis.config.BuildConfiguration.StrictDepsMode;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder;
@@ -32,6 +34,7 @@ import com.google.devtools.build.lib.rules.java.JavaRuleOutputJarsProvider.Outpu
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
+import javax.annotation.Nullable;
/**
* A class to create Java compile actions in a way that is consistent with java_library. Rules that
@@ -156,16 +159,29 @@ public final class JavaLibraryHelper {
}
/**
- * Creates the compile actions. Also fills in the {@link JavaRuleOutputJarsProvider.Builder} with
- * the corresponding compilation outputs.
+ * Creates the compile actions (including the ones for ijar and source jar). Also fills in the
+ * {@link JavaRuleOutputJarsProvider.Builder} with the corresponding compilation outputs.
+ *
+ * @param semantics implementation specific java rules semantics
+ * @param javaToolchainProvider used for retrieving misc java tools
+ * @param hostJavabase the target of the host javabase used to retrieve the java executable and
+ * its necessary inputs
+ * @param jacocoInstrumental jacoco jars needed when running coverage
+ * @param outputJarsBuilder populated with the outputs of the created actions
+ * @param outputSourceJar if not-null, the output of an source jar action that will be created
*/
public JavaCompilationArtifacts build(
JavaSemantics semantics,
JavaToolchainProvider javaToolchainProvider,
- NestedSet<Artifact> hostJavabase,
+ TransitiveInfoCollection hostJavabase,
Iterable<Artifact> jacocoInstrumental,
- JavaRuleOutputJarsProvider.Builder outputJarsBuilder) {
+ JavaRuleOutputJarsProvider.Builder outputJarsBuilder,
+ boolean createOutputSourceJar,
+ @Nullable Artifact outputSourceJar) {
Preconditions.checkState(output != null, "must have an output file; use setOutput()");
+ Preconditions.checkState(
+ !createOutputSourceJar || outputSourceJar != null,
+ "outputSourceJar cannot be null when createOutputSourceJar is true");
JavaTargetAttributes.Builder attributes = new JavaTargetAttributes.Builder(semantics);
attributes.addSourceJars(sourceJars);
attributes.addSourceFiles(sourceFiles);
@@ -185,11 +201,12 @@ public final class JavaLibraryHelper {
attributes, deps);
}
+ NestedSet<Artifact> hostJavabaseArtifacts = getMiddleManFor(hostJavabase);
JavaCompilationArtifacts.Builder artifactsBuilder = new JavaCompilationArtifacts.Builder();
JavaCompilationHelper helper =
new JavaCompilationHelper(ruleContext, semantics, javacOpts, attributes,
javaToolchainProvider,
- hostJavabase,
+ hostJavabaseArtifacts,
jacocoInstrumental);
Artifact outputDepsProto = helper.createOutputDepsProtoArtifact(output, artifactsBuilder);
helper.createCompileAction(
@@ -198,17 +215,35 @@ public final class JavaLibraryHelper {
null /* gensrcOutputJar */,
outputDepsProto,
null /* outputMetadata */);
- Artifact iJar = helper.createCompileTimeJarAction(output, artifactsBuilder);
artifactsBuilder.addRuntimeJar(output);
+ Artifact iJar = helper.createCompileTimeJarAction(output, artifactsBuilder);
+ if (createOutputSourceJar) {
+ helper.createSourceJarAction(outputSourceJar, null,
+ javaToolchainProvider, hostJavabaseArtifacts,
+ JavaCommon.getHostJavaExecutable(ruleContext, hostJavabase));
+ }
+ ImmutableList<Artifact> outputSourceJars =
+ outputSourceJar == null ? ImmutableList.of() : ImmutableList.of(outputSourceJar);
outputJarsBuilder
- .addOutputJar(new OutputJar(output, iJar, sourceJars))
+ .addOutputJar(new OutputJar(output, iJar, outputSourceJars))
.setJdeps(outputDepsProto);
return artifactsBuilder.build();
}
+ private static NestedSet<Artifact> getMiddleManFor(TransitiveInfoCollection prereq) {
+ if (prereq == null) {
+ return NestedSetBuilder.emptySet(Order.STABLE_ORDER);
+ }
+ MiddlemanProvider provider = prereq.getProvider(MiddlemanProvider.class);
+ if (provider == null) {
+ return NestedSetBuilder.emptySet(Order.STABLE_ORDER);
+ }
+ return provider.getMiddlemanArtifact();
+ }
+
/**
* Returns a JavaCompilationArgsProvider that fully encapsulates this compilation, based on the
* result of a call to build(). (that is, it contains the compile-time and runtime jars, separated
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaSkylarkCommon.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaSkylarkCommon.java
index a061157513..36a876c78c 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaSkylarkCommon.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaSkylarkCommon.java
@@ -20,7 +20,6 @@ import com.google.common.collect.Iterables;
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.analysis.ConfiguredTarget;
import com.google.devtools.build.lib.analysis.FilesToRunProvider;
-import com.google.devtools.build.lib.analysis.MiddlemanProvider;
import com.google.devtools.build.lib.analysis.RuleContext;
import com.google.devtools.build.lib.analysis.Runfiles;
import com.google.devtools.build.lib.analysis.actions.CustomCommandLine;
@@ -403,7 +402,11 @@ public class JavaSkylarkCommon {
ConfiguredTarget javaToolchain,
ConfiguredTarget hostJavabase,
SkylarkList<Artifact> sourcepathEntries,
- SkylarkList<Artifact> resources) throws EvalException {
+ SkylarkList<Artifact> resources) throws EvalException, InterruptedException {
+ if (sourceJars.isEmpty() && sourceFiles.isEmpty() && exports.isEmpty()) {
+ throw new EvalException(
+ null, "source_jars, sources and exports cannot be simultaneous empty");
+ }
JavaLibraryHelper helper =
new JavaLibraryHelper(skylarkRuleContext.getRuleContext())
@@ -421,25 +424,28 @@ public class JavaSkylarkCommon {
helper.addAllDeps(depsCompilationArgsProviders);
helper.addAllExports(exportsCompilationArgsProviders);
helper.setCompilationStrictDepsMode(getStrictDepsMode(strictDepsMode.toUpperCase()));
- MiddlemanProvider hostJavabaseProvider = hostJavabase.getProvider(MiddlemanProvider.class);
helper.addAllPlugins(
JavaInfo.fetchProvidersFromList(plugins, JavaPluginInfoProvider.class));
helper.addAllPlugins(JavaInfo.fetchProvidersFromList(deps, JavaPluginInfoProvider.class));
- NestedSet<Artifact> hostJavabaseArtifacts =
- hostJavabaseProvider == null
- ? NestedSetBuilder.emptySet(Order.STABLE_ORDER)
- : hostJavabaseProvider.getMiddlemanArtifact();
- JavaToolchainProvider javaToolchainProvider = getJavaToolchainProvider(javaToolchain);
JavaRuleOutputJarsProvider.Builder outputJarsBuilder = JavaRuleOutputJarsProvider.builder();
+
+ boolean generateMergedSourceJar = (sourceJars.size() > 1 || !sourceFiles.isEmpty())
+ || (sourceJars.isEmpty() && sourceFiles.isEmpty() && !exports.isEmpty());
+ Artifact outputSourceJar =
+ generateMergedSourceJar ? getSourceJar(skylarkRuleContext) : sourceJars.get(0);
+
JavaCompilationArtifacts artifacts =
helper.build(
javaSemantics,
- javaToolchainProvider,
- hostJavabaseArtifacts,
+ getJavaToolchainProvider(javaToolchain),
+ hostJavabase,
SkylarkList.createImmutable(ImmutableList.of()),
- outputJarsBuilder);
+ outputJarsBuilder,
+ /*createOutputSourceJar*/ generateMergedSourceJar,
+ outputSourceJar);
+
JavaCompilationArgsProvider javaCompilationArgsProvider =
helper.buildCompilationArgsProvider(artifacts, true);
Runfiles runfiles =
@@ -456,15 +462,30 @@ public class JavaSkylarkCommon {
JavaPluginInfoProvider.class, exports)
));
+ ImmutableList<Artifact> outputSourceJars = ImmutableList.of(outputSourceJar);
+
+ NestedSetBuilder<Artifact> transitiveSourceJars =
+ NestedSetBuilder.<Artifact>stableOrder().addAll(outputSourceJars);
+ for (JavaSourceJarsProvider sourceJarsProvider :
+ JavaInfo.getProvidersFromListOfJavaProviders(JavaSourceJarsProvider.class, deps)) {
+ transitiveSourceJars.addTransitive(sourceJarsProvider.getTransitiveSourceJars());
+ }
+
return JavaInfo.Builder.create()
.addProvider(JavaCompilationArgsProvider.class, javaCompilationArgsProvider)
- .addProvider(JavaSourceJarsProvider.class, createJavaSourceJarsProvider(sourceJars))
+ .addProvider(JavaSourceJarsProvider.class,
+ createJavaSourceJarsProvider(outputSourceJars, transitiveSourceJars.build()))
.addProvider(JavaRuleOutputJarsProvider.class, outputJarsBuilder.build())
.addProvider(JavaRunfilesProvider.class, new JavaRunfilesProvider(runfiles))
.addProvider(JavaPluginInfoProvider.class, transitivePluginsProvider)
.build();
}
+ private static Artifact getSourceJar(SkylarkRuleContext skylarkRuleContext) throws EvalException {
+ return skylarkRuleContext.getRuleContext()
+ .getBinArtifact("lib" + skylarkRuleContext.getLabel().getName() + "-src.jar");
+ }
+
private static Artifact buildIjar(
SkylarkActionFactory actions,
Artifact inputJar,
@@ -487,13 +508,13 @@ public class JavaSkylarkCommon {
return interfaceJar;
}
/**
- * Creates a {@link JavaSourceJarsProvider} from the given list of source jars.
+ * Creates a {@link JavaSourceJarsProvider} from the given lists of source jars.
*/
- private static JavaSourceJarsProvider createJavaSourceJarsProvider(List<Artifact> sourceJars) {
+ private static JavaSourceJarsProvider createJavaSourceJarsProvider(
+ List<Artifact> sourceJars, NestedSet<Artifact> transitiveSourceJars) {
NestedSet<Artifact> javaSourceJars =
NestedSetBuilder.<Artifact>stableOrder().addAll(sourceJars).build();
- return JavaSourceJarsProvider.create(
- NestedSetBuilder.<Artifact>emptySet(Order.STABLE_ORDER), javaSourceJars);
+ return JavaSourceJarsProvider.create(transitiveSourceJars, javaSourceJars);
}
@SkylarkCallable(
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/SingleJarActionBuilder.java b/src/main/java/com/google/devtools/build/lib/rules/java/SingleJarActionBuilder.java
index 61ee42d124..1897453608 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/SingleJarActionBuilder.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/SingleJarActionBuilder.java
@@ -28,7 +28,7 @@ import com.google.devtools.build.lib.analysis.actions.ParamFileInfo;
import com.google.devtools.build.lib.analysis.actions.SpawnAction;
import com.google.devtools.build.lib.collect.nestedset.NestedSet;
import com.google.devtools.build.lib.concurrent.ThreadSafety.Immutable;
-import javax.annotation.Nullable;
+import com.google.devtools.build.lib.vfs.PathFragment;
/**
* Helper class to create singlejar actions - singlejar can merge multiple zip files without
@@ -45,19 +45,22 @@ public final class SingleJarActionBuilder {
"--warn_duplicate_resources");
/** Constructs the base spawn for a singlejar action. */
- private static SpawnAction.Builder singleJarActionBuilder(RuleContext ruleContext) {
- Artifact singleJar = JavaToolchainProvider.from(ruleContext).getSingleJar();
+ private static SpawnAction.Builder singleJarActionBuilder(
+ JavaToolchainProvider provider,
+ NestedSet<Artifact> hostJavabaseInputs,
+ PathFragment hostJavaExecutable) {
+ Artifact singleJar = provider.getSingleJar();;
SpawnAction.Builder builder = new SpawnAction.Builder();
// If singlejar's name ends with .jar, it is Java application, otherwise it is native.
// TODO(asmundak): once https://github.com/bazelbuild/bazel/issues/2241 is fixed (that is,
// the native singlejar is used on windows) remove support for the Java implementation
if (singleJar.getFilename().endsWith(".jar")) {
builder
- .addTransitiveInputs(JavaHelper.getHostJavabaseInputs(ruleContext))
+ .addTransitiveInputs(hostJavabaseInputs)
.setJarExecutable(
- JavaCommon.getHostJavaExecutable(ruleContext),
+ hostJavaExecutable,
singleJar,
- JavaToolchainProvider.from(ruleContext).getJvmOptions())
+ provider.getJvmOptions())
.setExecutionInfo(ExecutionRequirements.WORKER_MODE_ENABLED);
} else {
builder.setExecutable(singleJar);
@@ -68,26 +71,50 @@ public final class SingleJarActionBuilder {
/**
* Creates an Action that packages files into a Jar file.
*
- * @param semantics the current Java semantics, which must be non-{@code null} if {@code
- * resources} is non-empty
- * @param resources the resources to put into the Jar
+ * @param resources the resources to put into the Jar.
* @param resourceJars the resource jars to merge into the jar
* @param outputJar the Jar to create
*/
public static void createSourceJarAction(
RuleContext ruleContext,
- @Nullable JavaSemantics semantics,
+ JavaSemantics semantics,
ImmutableCollection<Artifact> resources,
NestedSet<Artifact> resourceJars,
Artifact outputJar) {
+ createSourceJarAction(
+ ruleContext, semantics, resources, resourceJars, outputJar,
+ JavaToolchainProvider.from(ruleContext),
+ JavaHelper.getHostJavabaseInputs(ruleContext),
+ JavaCommon.getHostJavaExecutable(ruleContext));
+ }
+
+ /**
+ * Creates an Action that packages files into a Jar file.
+ *
+ * @param resources the resources to put into the Jar.
+ * @param resourceJars the resource jars to merge into the jar
+ * @param outputJar the Jar to create
+ * @param toolchainProvider is used to retrieve jvm options
+ * @param hostJavabaseInputs Artifacts required to invoke java executable in the created action
+ * @param hostJavaExecutable the jar executable of the created action
+ */
+ public static void createSourceJarAction(
+ RuleContext ruleContext,
+ JavaSemantics semantics,
+ ImmutableCollection<Artifact> resources,
+ NestedSet<Artifact> resourceJars,
+ Artifact outputJar,
+ JavaToolchainProvider toolchainProvider,
+ NestedSet<Artifact> hostJavabaseInputs,
+ PathFragment hostJavaExecutable) {
requireNonNull(ruleContext);
requireNonNull(resourceJars);
requireNonNull(outputJar);
if (!resources.isEmpty()) {
requireNonNull(semantics);
}
- SpawnAction.Builder builder =
- singleJarActionBuilder(ruleContext)
+ SpawnAction.Builder builder = singleJarActionBuilder(
+ toolchainProvider, hostJavabaseInputs, hostJavaExecutable)
.addOutput(outputJar)
.addInputs(resources)
.addTransitiveInputs(resourceJars)
@@ -111,15 +138,18 @@ public final class SingleJarActionBuilder {
requireNonNull(jars);
requireNonNull(output);
SpawnAction.Builder builder =
- singleJarActionBuilder(ruleContext)
- .addOutput(output)
- .addInputs(jars)
- .addCommandLine(
- sourceJarCommandLine(
- output, /* semantics= */ null, /* resources= */ ImmutableList.of(), jars),
- ParamFileInfo.builder(ParameterFileType.SHELL_QUOTED).setUseAlways(true).build())
- .setProgressMessage("Building singlejar jar %s", output.prettyPrint())
- .setMnemonic("JavaSingleJar");
+ singleJarActionBuilder(
+ JavaToolchainProvider.from(ruleContext),
+ JavaHelper.getHostJavabaseInputs(ruleContext),
+ JavaCommon.getHostJavaExecutable(ruleContext))
+ .addOutput(output)
+ .addInputs(jars)
+ .addCommandLine(
+ sourceJarCommandLine(
+ output, /* semantics= */ null, /* resources= */ ImmutableList.of(), jars),
+ ParamFileInfo.builder(ParameterFileType.SHELL_QUOTED).setUseAlways(true).build())
+ .setProgressMessage("Building singlejar jar %s", output.prettyPrint())
+ .setMnemonic("JavaSingleJar");
ruleContext.registerAction(builder.build(ruleContext));
}
@@ -146,3 +176,4 @@ public final class SingleJarActionBuilder {
semantics.getDefaultJavaResourcePath(resource.getRootRelativePath()));
}
}
+
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 7d87f9891d..e25bd120da 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
@@ -264,13 +264,14 @@ public class JavaLiteProtoAspect extends NativeAspectClass implements Configured
}
}
- JavaCompilationArtifacts artifacts =
- helper.build(
- javaSemantics,
- JavaCompilationHelper.getJavaToolchainProvider(ruleContext),
- JavaHelper.getHostJavabaseInputs(ruleContext),
- JavaCompilationHelper.getInstrumentationJars(ruleContext),
- JavaRuleOutputJarsProvider.builder());
+ JavaCompilationArtifacts artifacts = helper.build(
+ javaSemantics,
+ JavaCompilationHelper.getJavaToolchainProvider(ruleContext),
+ JavaHelper.getHostJavabaseTarget(ruleContext),
+ JavaCompilationHelper.getInstrumentationJars(ruleContext),
+ JavaRuleOutputJarsProvider.builder(),
+ /*createOutputSourceJar*/false,
+ /*outputSourceJar=*/ null);
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 4603add72f..7367c1be72 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
@@ -306,9 +306,11 @@ public class JavaProtoAspect extends NativeAspectClass implements ConfiguredAspe
helper.build(
javaSemantics,
JavaCompilationHelper.getJavaToolchainProvider(ruleContext),
- JavaHelper.getHostJavabaseInputs(ruleContext),
+ JavaHelper.getHostJavabaseTarget(ruleContext),
JavaCompilationHelper.getInstrumentationJars(ruleContext),
- JavaRuleOutputJarsProvider.builder()),
+ JavaRuleOutputJarsProvider.builder(),
+ /*createOutputSourceJar*/false,
+ /*outputSourceJar=*/ null),
true /* isReportedAsStrict */);
}