Skip to content
This repository was archived by the owner on Nov 10, 2023. It is now read-only.

Commit c75bb91

Browse files
shs96csdwilsh
authored andcommitted
Set the sourcepath properly when compiling.
Summary: javac will scan the classpath for any missing source files. While this is interesting behaviour, it's not what we want. As such, set the sourcepath to a value that will work. This closes #244 on GitHub. Test Plan: buck test --all
1 parent d2b64c6 commit c75bb91

File tree

5 files changed

+42
-1
lines changed

5 files changed

+42
-1
lines changed

src/com/facebook/buck/java/JavacOptions.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ public Javac getJavac() {
9292
ProcessExecutorParams params = ImmutableProcessExecutorParams.builder()
9393
.setCommand(ImmutableList.of(externalJavac.get().toString(), "-version"))
9494
.build();
95-
ProcessExecutor.Result result = null;
95+
ProcessExecutor.Result result;
9696
try {
9797
result = getProcessExecutor().get().launchAndExecute(params);
9898
} catch (InterruptedException | IOException e) {
@@ -119,6 +119,9 @@ public void appendOptionsToList(
119119
optionsBuilder.add("-source", getSourceLevel());
120120
optionsBuilder.add("-target", getTargetLevel());
121121

122+
// Set the sourcepath to stop us reading source files out of jars by mistake.
123+
optionsBuilder.add("-sourcepath", "");
124+
122125
if (isDebug()) {
123126
optionsBuilder.add("-g");
124127
}

test/com/facebook/buck/java/DefaultJavaLibraryIntegrationTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,23 @@ public void ensureChangingDepFromProvidedToTransitiveTriggersRebuild() throws IO
381381
workspace.getBuildLog().assertTargetBuiltLocally("//:library");
382382
}
383383

384+
@Test
385+
public void ensureThatSourcePathIsSetSensibly() throws IOException {
386+
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(
387+
this,
388+
"sourcepath",
389+
tmp);
390+
workspace.setUp();
391+
392+
ProcessResult result = workspace.runBuckBuild("//:b");
393+
394+
// This should fail, since we expect the symbol for A not to be found.
395+
result.assertFailure();
396+
String stderr = result.getStderr();
397+
398+
assertTrue(stderr, stderr.contains("cannot find symbol"));
399+
}
400+
384401
/**
385402
* Asserts that the specified file exists and returns its contents.
386403
*/
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// In the default package
2+
3+
class A {
4+
5+
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// Default package
2+
3+
class B extends A {
4+
}
5+
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
java_library(
2+
name = 'a',
3+
resources = ['A.java'],
4+
)
5+
6+
java_library(
7+
name = 'b',
8+
srcs = ['B.java'],
9+
deps = [':a'],
10+
)
11+

0 commit comments

Comments
 (0)