Skip to content

Commit

Permalink
Re-enabling passing -sourcepath via javacopts.
Browse files Browse the repository at this point in the history
This is needed until java_common.compile will be strong enough to replace
java_library, exposing all its features.

PiperOrigin-RevId: 155773169
  • Loading branch information
iirina authored and kchodorow committed May 11, 2017
1 parent aad0bd0 commit 1a57d29
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Deque;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
Expand Down Expand Up @@ -110,6 +111,7 @@ private void processCommandlineArgs(Deque<String> argQueue) throws InvalidComman
// otherwise we have to do something like adding a "--"
// terminator to the passed arguments.
collectFlagArguments(javacOpts, argQueue, "--");
sourcePathFromJavacOpts();
break;
case "--direct_dependency":
{
Expand Down Expand Up @@ -220,6 +222,18 @@ private void processCommandlineArgs(Deque<String> argQueue) throws InvalidComman
}
}

private void sourcePathFromJavacOpts() {
Iterator<String> it = javacOpts.iterator();
while (it.hasNext()) {
String curr = it.next();
if (curr.equals("-sourcepath") && it.hasNext()) {
it.remove();
sourcePath = it.next();
it.remove();
}
}
}

private JarOwner parseJarOwner(String line) {
List<String> ownerStringParts = SPACE_SPLITTER.splitToList(line);
JarOwner owner;
Expand Down
36 changes: 36 additions & 0 deletions src/test/shell/bazel/bazel_java_test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,42 @@ function test_build_hello_world() {
bazel build //java/main:main &> $TEST_log || fail "build failed"
}

function test_build_with_sourcepath() {
mkdir -p g
cat >g/A.java <<'EOF'
package g;
public class A {
public A() {
new B();
}
}
EOF

cat >g/B.java <<'EOF'
package g;
public class B {
public B() {
}
}
EOF

cat >g/BUILD <<'EOF'
genrule(
name = "stub",
srcs = ["B.java"],
outs = ["B.jar"],
cmd = "zip $@ $(SRCS)",
)
java_library(
name = "test",
srcs = ["A.java"],
javacopts = ["-sourcepath $(GENDIR)/$(location :stub)", "-implicit:none"],
deps = [":stub"]
)
EOF
bazel build //g:test >$TEST_log || fail "Failed to build //g:test"
}

function test_java_common_compile_sourcepath() {
# TODO(bazel-team): Enable this for Java 7 when VanillaJavaBuilder supports --sourcepath.
JAVA_VERSION="1.$(bazel query --output=build '@bazel_tools//tools/jdk:toolchain' | grep source_version | cut -d '"' -f 2)"
Expand Down

1 comment on commit 1a57d29

@juhalindfors
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a list of open issues that needs completion before java_common.compile can be used instead of java_library?

Please sign in to comment.