Skip to content

Commit 3212bc0

Browse files
committed
Don't fail the build if compiling a module without direct jars.
Closes #18
1 parent 3ab299e commit 3212bc0

File tree

2 files changed

+18
-8
lines changed

2 files changed

+18
-8
lines changed

compiler/src/main/buildjar/com/google/devtools/build/buildjar/BazelEcjJavaBuilder.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package com.google.devtools.build.buildjar;
1616

17+
import static com.google.devtools.build.buildjar.StrictDepsClasspathJavaLibraryBuilder.OPTION_STRICT_DEPS_BUILDER;
18+
1719
import java.io.IOException;
1820
import java.io.OutputStreamWriter;
1921
import java.io.PrintWriter;
@@ -28,7 +30,6 @@
2830
import com.google.common.collect.ImmutableList;
2931
import com.google.devtools.build.buildjar.javac.BlazeJavacResult;
3032
import com.google.devtools.build.buildjar.javac.BlazeJavacResult.Status;
31-
import com.google.devtools.build.buildjar.javac.FormattedDiagnostic;
3233
import com.google.devtools.build.buildjar.javac.JavacOptions;
3334
import com.google.devtools.build.buildjar.javac.plugins.BlazeJavaCompilerPlugin;
3435
import com.google.devtools.build.buildjar.javac.plugins.dependency.DependencyModule;
@@ -90,7 +91,7 @@ public int parseAndBuild(List<String> args, PrintWriter pw) {
9091
}
9192

9293
private Supplier<SimpleJavaLibraryBuilder> getBuilder(JavaLibraryBuildRequest build) {
93-
if(build.getJavacOpts().contains("-Xecj_use_direct_deps_only"))
94+
if(build.getJavacOpts().contains(OPTION_STRICT_DEPS_BUILDER))
9495
return StrictDepsClasspathJavaLibraryBuilder::new;
9596
return build.getDependencyModule().reduceClasspath()
9697
? ReducedClasspathJavaLibraryBuilder::new

compiler/src/main/buildjar/com/google/devtools/build/buildjar/StrictDepsClasspathJavaLibraryBuilder.java

+15-6
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@
3131
*/
3232
public class StrictDepsClasspathJavaLibraryBuilder extends SimpleJavaLibraryBuilder {
3333

34+
static final String OPTION_STRICT_DEPS_BUILDER = "-Xecj_use_direct_deps_only";
35+
3436
/**
3537
* Attempts to minimize the compile-time classpath before invoking javac,
3638
* falling back to a regular compile.
@@ -41,13 +43,20 @@ public class StrictDepsClasspathJavaLibraryBuilder extends SimpleJavaLibraryBuil
4143
*/
4244
@Override
4345
BlazeJavacResult compileSources(JavaLibraryBuildRequest build, JavacRunner javacRunner) throws IOException {
44-
if(build.getDependencyModule().directJars().isEmpty()) {
45-
// in this case the direct jars list is empty
46-
return BlazeJavacResult.error("No direct jars information supplied by Bazel. Please adjust Bazel settings to allow submission of direct dependency information (e.g., don't use --strict_java_deps=off).");
47-
}
46+
ImmutableList<Path> compressedClasspath;
47+
switch (build.getDependencyModule().getStrictJavaDeps()) {
48+
case OFF:
49+
// this does nor really make sense but the user selected to do so
50+
compressedClasspath = build.getClassPath();
51+
break;
4852

49-
ImmutableList<Path> compressedClasspath = build.getDependencyModule().directJars().stream()
50-
.collect(toImmutableList());
53+
case ERROR:
54+
case WARN:
55+
default:
56+
// compile with the direct jars only
57+
compressedClasspath = build.getDependencyModule().directJars().stream().collect(toImmutableList());
58+
break;
59+
}
5160

5261
BlazeJavacResult result = javacRunner.invokeJavac(build.toBlazeJavacArguments(compressedClasspath));
5362

0 commit comments

Comments
 (0)