aboutsummaryrefslogtreecommitdiffhomepage
path: root/src/main/java/com/google/devtools/build/lib/rules/java
diff options
context:
space:
mode:
authorGravatar elenairina <elenairina@google.com>2018-06-29 08:10:12 -0700
committerGravatar Copybara-Service <copybara-piper@google.com>2018-06-29 08:11:27 -0700
commit1458c61f6b458747906dec95b3592bf9b3eb6c91 (patch)
tree1ba931864af3242475c26e06fe4a2b5ee47d895a /src/main/java/com/google/devtools/build/lib/rules/java
parentc816b89a2224c3c318f1228755ef41c53975f45c (diff)
[java_common.compile] Always generate a source jar.
[Rolling forward https://github.com/bazelbuild/bazel/commit/c4e128e2c6d8cacaeba034d6a3195796d50f1745] java_common.compile doesn't generate the output source jar when a source jar is the only input for the compilation. This is wrong because the source jar can include APT generated sources. It is also inconsistent with java_library and leads to inconsistent Skylark rules where a declared output will not always have a generating action. This new behavior is guarded by a new flag --incompatible_generate_javacommon_source_jar. RELNOTES: None. PiperOrigin-RevId: 202648346
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/rules/java')
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaInfoBuildHelper.java26
-rw-r--r--src/main/java/com/google/devtools/build/lib/rules/java/JavaSkylarkCommon.java6
2 files changed, 21 insertions, 11 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfoBuildHelper.java b/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfoBuildHelper.java
index f1c2b699a7..802d86ca98 100644
--- a/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfoBuildHelper.java
+++ b/src/main/java/com/google/devtools/build/lib/rules/java/JavaInfoBuildHelper.java
@@ -40,6 +40,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.events.Location;
import com.google.devtools.build.lib.rules.java.JavaCompilationArgsProvider.ClasspathType;
+import com.google.devtools.build.lib.syntax.Environment;
import com.google.devtools.build.lib.syntax.EvalException;
import com.google.devtools.build.lib.syntax.SkylarkList;
import com.google.devtools.build.lib.vfs.FileSystemUtils;
@@ -422,7 +423,8 @@ final class JavaInfoBuildHelper {
SkylarkList<Artifact> sourcepathEntries,
SkylarkList<Artifact> resources,
Boolean neverlink,
- JavaSemantics javaSemantics)
+ JavaSemantics javaSemantics,
+ Environment environment)
throws EvalException {
if (sourceJars.isEmpty() && sourceFiles.isEmpty() && exports.isEmpty()) {
throw new EvalException(
@@ -469,13 +471,19 @@ final class JavaInfoBuildHelper {
JavaRuleOutputJarsProvider.Builder outputJarsBuilder = JavaRuleOutputJarsProvider.builder();
- boolean generateMergedSourceJar =
- (sourceJars.size() > 1 || !sourceFiles.isEmpty())
- || (sourceJars.isEmpty() && sourceFiles.isEmpty() && !exports.isEmpty());
- Artifact outputSourceJar =
- generateMergedSourceJar
- ? getSourceJar(skylarkRuleContext.getRuleContext(), outputJar)
- : sourceJars.get(0);
+ boolean createOutputSourceJar;
+ Artifact outputSourceJar;
+ if (environment.getSemantics().incompatibleGenerateJavaCommonSourceJar()) {
+ outputSourceJar = getSourceJar(skylarkRuleContext.getRuleContext(), outputJar);
+ createOutputSourceJar = true;
+ } else {
+ createOutputSourceJar = (sourceJars.size() > 1 || !sourceFiles.isEmpty())
+ || (sourceJars.isEmpty() && sourceFiles.isEmpty() && !exports.isEmpty());
+ outputSourceJar =
+ createOutputSourceJar
+ ? getSourceJar(skylarkRuleContext.getRuleContext(), outputJar)
+ : sourceJars.get(0);
+ }
JavaInfo.Builder javaInfoBuilder = JavaInfo.Builder.create();
JavaCompilationArtifacts artifacts =
@@ -485,7 +493,7 @@ final class JavaInfoBuildHelper {
javaRuntimeInfo,
SkylarkList.createImmutable(ImmutableList.of()),
outputJarsBuilder,
- /*createOutputSourceJar=*/ generateMergedSourceJar,
+ /*createOutputSourceJar=*/ createOutputSourceJar,
outputSourceJar,
javaInfoBuilder,
// Include JavaGenJarsProviders from both deps and exports in the JavaGenJarsProvider
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 b44fb1138a..1a7d590f45 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
@@ -97,7 +97,8 @@ public class JavaSkylarkCommon implements JavaCommonApi<Artifact, JavaInfo, Skyl
ConfiguredTarget hostJavabase,
SkylarkList<Artifact> sourcepathEntries,
SkylarkList<Artifact> resources,
- Boolean neverlink) throws EvalException, InterruptedException {
+ Boolean neverlink,
+ Environment environment) throws EvalException, InterruptedException {
return JavaInfoBuildHelper.getInstance()
.createJavaCompileAction(
@@ -116,7 +117,8 @@ public class JavaSkylarkCommon implements JavaCommonApi<Artifact, JavaInfo, Skyl
sourcepathEntries,
resources,
neverlink,
- javaSemantics);
+ javaSemantics,
+ environment);
}
@Override