This repository was archived by the owner on Jan 11, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 2 files changed +50
-0
lines changed
java_tools/buildjar/java/com/google/devtools/build/buildjar Expand file tree Collapse file tree 2 files changed +50
-0
lines changed Original file line number Diff line number Diff line change 2727import java .util .Deque ;
2828import java .util .HashMap ;
2929import java .util .HashSet ;
30+ import java .util .Iterator ;
3031import java .util .LinkedHashMap ;
3132import java .util .List ;
3233import 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 ;
Original file line number Diff line number Diff 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) "
You can’t perform that action at this time.
0 commit comments