Permalink
Browse files

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
  • Loading branch information...
shs96c authored and sdwilsh committed Mar 4, 2015
1 parent d2b64c6 commit c75bb91f7d8eec8ea8ed86b598fb2ef3bb67a3bf
@@ -92,7 +92,7 @@ public Javac getJavac() {
ProcessExecutorParams params = ImmutableProcessExecutorParams.builder()
.setCommand(ImmutableList.of(externalJavac.get().toString(), "-version"))
.build();
ProcessExecutor.Result result = null;
ProcessExecutor.Result result;
try {
result = getProcessExecutor().get().launchAndExecute(params);
} catch (InterruptedException | IOException e) {
@@ -119,6 +119,9 @@ public void appendOptionsToList(
optionsBuilder.add("-source", getSourceLevel());
optionsBuilder.add("-target", getTargetLevel());
// Set the sourcepath to stop us reading source files out of jars by mistake.
optionsBuilder.add("-sourcepath", "");
if (isDebug()) {
optionsBuilder.add("-g");
}
@@ -381,6 +381,23 @@ public void ensureChangingDepFromProvidedToTransitiveTriggersRebuild() throws IO
workspace.getBuildLog().assertTargetBuiltLocally("//:library");
}
@Test
public void ensureThatSourcePathIsSetSensibly() throws IOException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(
this,
"sourcepath",
tmp);
workspace.setUp();
ProcessResult result = workspace.runBuckBuild("//:b");
// This should fail, since we expect the symbol for A not to be found.
result.assertFailure();
String stderr = result.getStderr();
assertTrue(stderr, stderr.contains("cannot find symbol"));
}
/**
* Asserts that the specified file exists and returns its contents.
*/
@@ -0,0 +1,5 @@
// In the default package
class A {
}
@@ -0,0 +1,5 @@
// Default package
class B extends A {
}
@@ -0,0 +1,11 @@
java_library(
name = 'a',
resources = ['A.java'],
)
java_library(
name = 'b',
srcs = ['B.java'],
deps = [':a'],
)

0 comments on commit c75bb91

Please sign in to comment.