Search in sources :

Example 16 with ExecutableFinder

use of com.facebook.buck.io.ExecutableFinder in project buck by facebook.

the class OCamlIntegrationTest method testConfigInteropIncludes.

@Test
public void testConfigInteropIncludes() throws IOException, InterruptedException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "config_interop_includes", tmp);
    workspace.setUp();
    Path ocamlc = new ExecutableFinder(Platform.detect()).getExecutable(Paths.get("ocamlc"), ImmutableMap.copyOf(System.getenv()));
    ProcessExecutor.Result result = workspace.runCommand(ocamlc.toString(), "-where");
    assertEquals(0, result.getExitCode());
    String stdlibPath = result.getStdout().get();
    BuildTarget target = BuildTargetFactory.newInstance(workspace.getDestPath(), "//:test");
    BuildTarget binary = createOcamlLinkTarget(target);
    ImmutableSet<BuildTarget> targets = ImmutableSet.of(target, binary);
    // Points somewhere with no stdlib in it, so fails to find Pervasives
    workspace.runBuckCommand("build", target.toString()).assertFailure();
    BuckBuildLog buildLog = workspace.getBuildLog();
    assertThat(buildLog.getAllTargets(), Matchers.hasItems(targets.toArray(new BuildTarget[0])));
    buildLog.assertTargetCanceled(target.toString());
    buildLog.assertTargetCanceled(binary.toString());
    workspace.resetBuildLogFile();
    // Point to the real stdlib (from `ocamlc -where`)
    workspace.replaceFileContents(".buckconfig", "interop.includes=lib", "interop.includes=" + stdlibPath);
    workspace.runBuckCommand("build", target.toString()).assertSuccess();
    buildLog = workspace.getBuildLog();
    buildLog.assertTargetBuiltLocally(target.toString());
    buildLog.assertTargetBuiltLocally(binary.toString());
    workspace.resetBuildLogFile();
    // Remove the config, should default to a valid place
    workspace.replaceFileContents(".buckconfig", "interop.includes=" + stdlibPath, "");
    workspace.runBuckCommand("build", target.toString()).assertSuccess();
    buildLog = workspace.getBuildLog();
    buildLog.assertTargetBuiltLocally(target.toString());
    buildLog.assertTargetBuiltLocally(binary.toString());
}
Also used : Path(java.nio.file.Path) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) OcamlRuleBuilder.createStaticLibraryBuildTarget(com.facebook.buck.ocaml.OcamlRuleBuilder.createStaticLibraryBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) BuckBuildLog(com.facebook.buck.testutil.integration.BuckBuildLog) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) Test(org.junit.Test)

Example 17 with ExecutableFinder

use of com.facebook.buck.io.ExecutableFinder in project buck by facebook.

the class ParserConfigTest method whenParserPythonIsNotSetFallbackIsUsed.

@Test
public void whenParserPythonIsNotSetFallbackIsUsed() throws IOException {
    Path configPythonFile = temporaryFolder.newExecutableFile("python");
    // This sets the python.interpreter section, not parser.python_interpreter
    ParserConfig parserConfig = FakeBuckConfig.builder().setSections(ImmutableMap.of("python", ImmutableMap.of("interpreter", configPythonFile.toAbsolutePath().toString()))).build().getView(ParserConfig.class);
    assertEquals("Should return path to temp file.", configPythonFile.toAbsolutePath().toString(), parserConfig.getPythonInterpreter(new ExecutableFinder()));
}
Also used : Path(java.nio.file.Path) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) Test(org.junit.Test)

Example 18 with ExecutableFinder

use of com.facebook.buck.io.ExecutableFinder in project buck by facebook.

the class PythonBuckConfigTest method whenToolsPythonIsExecutableDirectoryThenItIsNotUsed.

@Test(expected = HumanReadableException.class)
public void whenToolsPythonIsExecutableDirectoryThenItIsNotUsed() throws IOException {
    Path configPythonFile = temporaryFolder.newFolder("python");
    PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().setSections(ImmutableMap.of("python", ImmutableMap.of("interpreter", configPythonFile.toAbsolutePath().toString()))).build(), new ExecutableFinder());
    config.getPythonInterpreter();
    fail("Should throw exception as python config is invalid.");
}
Also used : Path(java.nio.file.Path) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 19 with ExecutableFinder

use of com.facebook.buck.io.ExecutableFinder in project buck by facebook.

the class PythonBuckConfigTest method whenToolsPythonIsNonExecutableFileThenItIsNotUsed.

@Test(expected = HumanReadableException.class)
public void whenToolsPythonIsNonExecutableFileThenItIsNotUsed() throws IOException {
    assumeThat("On windows all files are executable.", Platform.detect(), is(not(Platform.WINDOWS)));
    Path configPythonFile = temporaryFolder.newFile("python");
    PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().setSections(ImmutableMap.of("python", ImmutableMap.of("interpreter", configPythonFile.toAbsolutePath().toString()))).build(), new ExecutableFinder());
    config.getPythonInterpreter();
    fail("Should throw exception as python config is invalid.");
}
Also used : Path(java.nio.file.Path) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 20 with ExecutableFinder

use of com.facebook.buck.io.ExecutableFinder in project buck by facebook.

the class PythonBuckConfigTest method whenMultiplePythonExecutablesOnPathFirstIsUsed.

@Test
public void whenMultiplePythonExecutablesOnPathFirstIsUsed() throws IOException {
    Path pythonA = temporaryFolder.newExecutableFile("python2");
    temporaryFolder2.newExecutableFile("python2");
    String path = temporaryFolder.getRoot().toAbsolutePath() + File.pathSeparator + temporaryFolder2.getRoot().toAbsolutePath();
    PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().setEnvironment(ImmutableMap.<String, String>builder().put("PATH", path).put("PATHEXT", "").build()).build(), new ExecutableFinder());
    assertEquals("Should return the first path", config.getPythonInterpreter(), pythonA.toAbsolutePath().toString());
}
Also used : Path(java.nio.file.Path) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Aggregations

ExecutableFinder (com.facebook.buck.io.ExecutableFinder)47 Path (java.nio.file.Path)28 Test (org.junit.Test)20 AlwaysFoundExecutableFinder (com.facebook.buck.io.AlwaysFoundExecutableFinder)13 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)9 PythonBuckConfig (com.facebook.buck.python.PythonBuckConfig)6 HumanReadableException (com.facebook.buck.util.HumanReadableException)6 CxxBuckConfig (com.facebook.buck.cxx.CxxBuckConfig)5 BuildTarget (com.facebook.buck.model.BuildTarget)5 ParserConfig (com.facebook.buck.parser.ParserConfig)5 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)5 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)5 BuckConfig (com.facebook.buck.cli.BuckConfig)4 DefaultProjectBuildFileParserFactory (com.facebook.buck.json.DefaultProjectBuildFileParserFactory)4 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)4 TestConsole (com.facebook.buck.testutil.TestConsole)4 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)4 FakeBuckConfig (com.facebook.buck.cli.FakeBuckConfig)3 Config (com.facebook.buck.config.Config)3 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)3