diff --git a/src/com/facebook/buck/jvm/java/ExternalJavac.java b/src/com/facebook/buck/jvm/java/ExternalJavac.java index 47f6f864f06..3e637956f57 100644 --- a/src/com/facebook/buck/jvm/java/ExternalJavac.java +++ b/src/com/facebook/buck/jvm/java/ExternalJavac.java @@ -58,14 +58,12 @@ /** javac implemented in a separate binary. */ public class ExternalJavac implements Javac { @AddToRuleKey private final Supplier javac; - private final Either actualPath; private final String shortName; public ExternalJavac(final Either pathToJavac) { if (pathToJavac.isRight() && pathToJavac.getRight() instanceof BuildTargetSourcePath) { BuildTargetSourcePath buildTargetPath = (BuildTargetSourcePath) pathToJavac.getRight(); this.shortName = buildTargetPath.getTarget().toString(); - this.actualPath = Either.ofRight(buildTargetPath); this.javac = MoreSuppliers.memoize( () -> @@ -89,7 +87,6 @@ public ImmutableMap getEnvironment( } else { PathSourcePath actualPath = pathToJavac.transform(path -> path, path -> (PathSourcePath) path); - this.actualPath = Either.ofLeft(actualPath); this.shortName = actualPath.toString(); this.javac = MoreSuppliers.memoize( @@ -117,11 +114,6 @@ public ImmutableMap getEnvironment( } } - @VisibleForTesting - Either getActualPath() { - return actualPath; - } - @Override public ImmutableList getCommandPrefix(SourcePathResolver resolver) { return javac.get().getCommandPrefix(resolver); @@ -198,9 +190,7 @@ public int buildClasses() throws InterruptedException { abiGenerationMode == AbiGenerationMode.CLASS, "Cannot compile ABI jars with external javac"); ImmutableList.Builder command = ImmutableList.builder(); - command.add( - actualPath.transform( - Object::toString, path -> sourcePathResolver.getAbsolutePath(path).toString())); + command.addAll(javac.get().getCommandPrefix(sourcePathResolver)); ImmutableList expandedSources; try { expandedSources = diff --git a/test/com/facebook/buck/jvm/java/JavacSpecTest.java b/test/com/facebook/buck/jvm/java/JavacSpecTest.java index 72485c41cd1..dd2cf466fbe 100644 --- a/test/com/facebook/buck/jvm/java/JavacSpecTest.java +++ b/test/com/facebook/buck/jvm/java/JavacSpecTest.java @@ -30,26 +30,35 @@ import com.facebook.buck.core.sourcepath.DefaultBuildTargetSourcePath; import com.facebook.buck.core.sourcepath.PathSourcePath; import com.facebook.buck.core.sourcepath.SourcePath; +import com.facebook.buck.core.sourcepath.resolver.SourcePathResolver; +import com.facebook.buck.core.sourcepath.resolver.impl.DefaultSourcePathResolver; import com.facebook.buck.model.BuildTargetFactory; import com.facebook.buck.rules.FakeSourcePath; import com.facebook.buck.testutil.FakeProjectFilesystem; +import com.facebook.buck.testutil.TemporaryPaths; import com.facebook.buck.util.types.Either; import com.google.common.collect.ImmutableList; +import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; import org.hamcrest.Matchers; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; public class JavacSpecTest { private ActionGraphBuilder graphBuilder; + private SourcePathResolver sourcePathResolver; private SourcePathRuleFinder ruleFinder; private JavacSpec.Builder specBuilder; + @Rule public TemporaryPaths tmp = new TemporaryPaths(); + @Before public void setUp() { graphBuilder = new TestActionGraphBuilder(); ruleFinder = new SourcePathRuleFinder(graphBuilder); + sourcePathResolver = DefaultSourcePathResolver.from(ruleFinder); specBuilder = JavacSpec.builder(); } @@ -70,33 +79,33 @@ public void returnsBuiltInJavacWhenCompilerArgHasDefault() { } @Test - public void returnsExternalCompilerIfJavacPathPresent() { - Path externalPath = Paths.get("/foo/bar/path/to/javac"); - SourcePath javacPath = FakeSourcePath.of(externalPath); + public void returnsExternalCompilerIfJavacPathPresent() throws IOException { + Path externalPath = tmp.newExecutableFile(); + SourcePath javacPath = FakeSourcePath.of(externalPath); specBuilder.setJavacPath(Either.ofRight(javacPath)); ExternalJavac javac = (ExternalJavac) getJavac(); - assertTrue(javac.getActualPath().isLeft()); - assertEquals(javacPath, javac.getActualPath().getLeft()); + + assertEquals( + ImmutableList.of(externalPath.toString()), javac.getCommandPrefix(sourcePathResolver)); } @Test - public void returnsExternalCompilerIfCompilerArgHasPath() { - Path externalJavac = Paths.get("/foo/bar/javac.exe").toAbsolutePath(); + public void returnsExternalCompilerIfCompilerArgHasPath() throws IOException { + Path externalJavac = tmp.newExecutableFile(); SourcePath sourcePath = FakeSourcePath.of(externalJavac.toString()); Either either = Either.ofRight(sourcePath); specBuilder.setCompiler(either); ExternalJavac javac = (ExternalJavac) getJavac(); - assertTrue(javac.getActualPath().isLeft()); - PathSourcePath actualPath = javac.getActualPath().getLeft(); - assertEquals(sourcePath, actualPath); + assertEquals( + ImmutableList.of(externalJavac.toString()), javac.getCommandPrefix(sourcePathResolver)); } @Test - public void compilerArgTakesPrecedenceOverJavacPathArg() { - Path externalJavacPath = Paths.get("/foo/bar/javac.exe").toAbsolutePath(); + public void compilerArgTakesPrecedenceOverJavacPathArg() throws IOException { + Path externalJavacPath = tmp.newExecutableFile(); SourcePath sourcePath = FakeSourcePath.of(externalJavacPath.toString()); Either either = Either.ofRight(sourcePath); @@ -105,8 +114,8 @@ public void compilerArgTakesPrecedenceOverJavacPathArg() { .setJavacPath(Either.ofLeft(FakeSourcePath.of("does-not-exist"))); ExternalJavac javac = (ExternalJavac) getJavac(); - assertTrue(javac.getActualPath().isLeft()); - assertEquals(sourcePath, javac.getActualPath().getLeft()); + assertEquals( + ImmutableList.of(externalJavacPath.toString()), javac.getCommandPrefix(sourcePathResolver)); } @Test