Skip to content
This repository was archived by the owner on Jan 11, 2024. It is now read-only.

Commit 1a57d29

Browse files
iirinakchodorow
authored andcommitted
Re-enabling passing -sourcepath via javacopts.
This is needed until java_common.compile will be strong enough to replace java_library, exposing all its features. PiperOrigin-RevId: 155773169
1 parent aad0bd0 commit 1a57d29

File tree

2 files changed

+50
-0
lines changed

2 files changed

+50
-0
lines changed

src/java_tools/buildjar/java/com/google/devtools/build/buildjar/OptionsParser.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
import java.util.Deque;
2828
import java.util.HashMap;
2929
import java.util.HashSet;
30+
import java.util.Iterator;
3031
import java.util.LinkedHashMap;
3132
import java.util.List;
3233
import java.util.Map;
@@ -110,6 +111,7 @@ private void processCommandlineArgs(Deque<String> argQueue) throws InvalidComman
110111
// otherwise we have to do something like adding a "--"
111112
// terminator to the passed arguments.
112113
collectFlagArguments(javacOpts, argQueue, "--");
114+
sourcePathFromJavacOpts();
113115
break;
114116
case "--direct_dependency":
115117
{
@@ -220,6 +222,18 @@ private void processCommandlineArgs(Deque<String> argQueue) throws InvalidComman
220222
}
221223
}
222224

225+
private void sourcePathFromJavacOpts() {
226+
Iterator<String> it = javacOpts.iterator();
227+
while (it.hasNext()) {
228+
String curr = it.next();
229+
if (curr.equals("-sourcepath") && it.hasNext()) {
230+
it.remove();
231+
sourcePath = it.next();
232+
it.remove();
233+
}
234+
}
235+
}
236+
223237
private JarOwner parseJarOwner(String line) {
224238
List<String> ownerStringParts = SPACE_SPLITTER.splitToList(line);
225239
JarOwner owner;

src/test/shell/bazel/bazel_java_test.sh

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,42 @@ function test_build_hello_world() {
105105
bazel build //java/main:main &> $TEST_log || fail "build failed"
106106
}
107107

108+
function test_build_with_sourcepath() {
109+
mkdir -p g
110+
cat >g/A.java <<'EOF'
111+
package g;
112+
public class A {
113+
public A() {
114+
new B();
115+
}
116+
}
117+
EOF
118+
119+
cat >g/B.java <<'EOF'
120+
package g;
121+
public class B {
122+
public B() {
123+
}
124+
}
125+
EOF
126+
127+
cat >g/BUILD <<'EOF'
128+
genrule(
129+
name = "stub",
130+
srcs = ["B.java"],
131+
outs = ["B.jar"],
132+
cmd = "zip $@ $(SRCS)",
133+
)
134+
java_library(
135+
name = "test",
136+
srcs = ["A.java"],
137+
javacopts = ["-sourcepath $(GENDIR)/$(location :stub)", "-implicit:none"],
138+
deps = [":stub"]
139+
)
140+
EOF
141+
bazel build //g:test >$TEST_log || fail "Failed to build //g:test"
142+
}
143+
108144
function test_java_common_compile_sourcepath() {
109145
# TODO(bazel-team): Enable this for Java 7 when VanillaJavaBuilder supports --sourcepath.
110146
JAVA_VERSION="1.$(bazel query --output=build '@bazel_tools//tools/jdk:toolchain' | grep source_version | cut -d '"' -f 2)"

0 commit comments

Comments
 (0)