Search in sources :

Example 11 with ExecutableFinder

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

the class CxxBinaryIntegrationTest method testChangingCompilerPathForcesRebuild.

@Test
public void testChangingCompilerPathForcesRebuild() throws Exception {
    assumeTrue(Platform.detect() != Platform.WINDOWS);
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "simple", tmp);
    workspace.setUp();
    workspace.enableDirCache();
    workspace.setupCxxSandboxing(sandboxSources);
    ProjectFilesystem filesystem = new ProjectFilesystem(workspace.getDestPath());
    BuildTarget target = BuildTargetFactory.newInstance("//foo:simple");
    BuildTarget linkTarget = CxxDescriptionEnhancer.createCxxLinkTarget(target, Optional.empty());
    // Get the real location of the compiler executable.
    String executable = Platform.detect() == Platform.MACOS ? "clang++" : "g++";
    Path executableLocation = new ExecutableFinder().getOptionalExecutable(Paths.get(executable), ImmutableMap.copyOf(System.getenv())).orElse(Paths.get("/usr/bin", executable));
    // Write script as faux clang++/g++ binary
    Path firstCompilerPath = tmp.newFolder("path1");
    Path firstCompiler = firstCompilerPath.resolve(executable);
    filesystem.writeContentsToPath("#!/bin/sh\n" + "exec " + executableLocation.toString() + " \"$@\"\n", firstCompiler);
    // Write script as slightly different faux clang++/g++ binary
    Path secondCompilerPath = tmp.newFolder("path2");
    Path secondCompiler = secondCompilerPath.resolve(executable);
    filesystem.writeContentsToPath("#!/bin/sh\n" + "exec " + executableLocation.toString() + " \"$@\"\n" + "# Comment to make hash different.\n", secondCompiler);
    // Make the second faux clang++/g++ binary executable
    MoreFiles.makeExecutable(secondCompiler);
    // Run two builds, each with different compiler "binaries".  In the first
    // instance, both binaries are in the PATH but the first binary is not
    // marked executable so is not picked up.
    workspace.runBuckCommandWithEnvironmentOverridesAndContext(workspace.getDestPath(), Optional.empty(), ImmutableMap.of("PATH", firstCompilerPath.toString() + pathSeparator + secondCompilerPath.toString() + pathSeparator + System.getenv("PATH")), "build", target.getFullyQualifiedName()).assertSuccess();
    workspace.resetBuildLogFile();
    // Now, make the first faux clang++/g++ binary executable.  In this second
    // instance, both binaries are still in the PATH but the first binary is
    // now marked executable and so is picked up; causing a rebuild.
    MoreFiles.makeExecutable(firstCompiler);
    workspace.runBuckCommandWithEnvironmentOverridesAndContext(workspace.getDestPath(), Optional.empty(), ImmutableMap.of("PATH", firstCompilerPath.toString() + pathSeparator + secondCompilerPath.toString() + pathSeparator + System.getenv("PATH")), "build", target.getFullyQualifiedName()).assertSuccess();
    // Make sure the binary change caused a rebuild.
    workspace.getBuildLog().assertTargetBuiltLocally(linkTarget.toString());
}
Also used : Path(java.nio.file.Path) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 12 with ExecutableFinder

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

the class HaskellTestUtils method assumeSystemCompiler.

/**
   * Assume that we can find a haskell compiler on the system.
   */
public static void assumeSystemCompiler() {
    HaskellBuckConfig fakeConfig = new HaskellBuckConfig(FakeBuckConfig.builder().build(), new ExecutableFinder());
    Optional<Path> compilerOptional = fakeConfig.getSystemCompiler();
    assumeTrue(compilerOptional.isPresent());
}
Also used : Path(java.nio.file.Path) ExecutableFinder(com.facebook.buck.io.ExecutableFinder)

Example 13 with ExecutableFinder

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

the class ExternalJavacEscaperTest method testSpecialCharsInSourcePath.

@Test
public void testSpecialCharsInSourcePath() throws IOException {
    assumeTrue(runOnWindows || Platform.detect() != Platform.WINDOWS);
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "external_javac", tmp);
    workspace.setUp();
    Path javac = new ExecutableFinder().getExecutable(Paths.get("javac"), ImmutableMap.copyOf(System.getenv()));
    assumeTrue(Files.exists(javac));
    workspace.replaceFileContents(".buckconfig", "@JAVAC@", javac.toString());
    workspace.move("java", badDir);
    workspace.runBuckCommand("clean").assertSuccess();
    workspace.runBuckCommand("build", String.format("//%s/com/example:example", badDir)).assertSuccess();
}
Also used : Path(java.nio.file.Path) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) Test(org.junit.Test)

Example 14 with ExecutableFinder

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

the class JavaSymbolFinderIntegrationTest method shouldFindTargetDefiningSymbol.

@Test
public void shouldFindTargetDefiningSymbol() throws IOException, InterruptedException {
    ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "symbol_finder", temporaryFolder);
    workspace.setUp();
    ProjectFilesystem projectFilesystem = new ProjectFilesystem(temporaryFolder.getRoot());
    ImmutableMap<String, String> environment = ImmutableMap.copyOf(System.getenv());
    Config rawConfig = Configs.createDefaultConfig(projectFilesystem.getRootPath());
    BuckConfig config = new BuckConfig(rawConfig, projectFilesystem, Architecture.detect(), Platform.detect(), environment, new DefaultCellPathResolver(projectFilesystem.getRootPath(), rawConfig));
    ParserConfig parserConfig = config.getView(ParserConfig.class);
    PythonBuckConfig pythonBuckConfig = new PythonBuckConfig(config, new ExecutableFinder());
    ImmutableSet<Description<?>> allDescriptions = KnownBuildRuleTypesTestUtil.getDefaultKnownBuildRuleTypes(projectFilesystem, environment).getAllDescriptions();
    SrcRootsFinder srcRootsFinder = new SrcRootsFinder(projectFilesystem);
    ProjectBuildFileParserFactory projectBuildFileParserFactory = new DefaultProjectBuildFileParserFactory(ProjectBuildFileParserOptions.builder().setProjectRoot(projectFilesystem.getRootPath()).setPythonInterpreter(pythonBuckConfig.getPythonInterpreter()).setAllowEmptyGlobs(parserConfig.getAllowEmptyGlobs()).setIgnorePaths(projectFilesystem.getIgnorePaths()).setBuildFileName(parserConfig.getBuildFileName()).setDefaultIncludes(parserConfig.getDefaultIncludes()).setDescriptions(allDescriptions).setBuildFileImportWhitelist(parserConfig.getBuildFileImportWhitelist()).build());
    BuckEventBus buckEventBus = BuckEventBusFactory.newInstance();
    JavaSymbolFinder finder = new JavaSymbolFinder(projectFilesystem, srcRootsFinder, DEFAULT_JAVAC_OPTIONS, new ConstructorArgMarshaller(new DefaultTypeCoercerFactory(ObjectMappers.newDefaultInstance())), projectBuildFileParserFactory, config, buckEventBus, new TestConsole(), environment);
    SetMultimap<String, BuildTarget> foundTargets = finder.findTargetsForSymbols(ImmutableSet.of("com.example.a.A"));
    assertEquals("JavaSymbolFinder failed to find the right target.", ImmutableSetMultimap.of("com.example.a.A", BuildTargetFactory.newInstance(projectFilesystem, "//java/com/example/a:a")), foundTargets);
}
Also used : PythonBuckConfig(com.facebook.buck.python.PythonBuckConfig) BuckEventBus(com.facebook.buck.event.BuckEventBus) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) DefaultCellPathResolver(com.facebook.buck.rules.DefaultCellPathResolver) Description(com.facebook.buck.rules.Description) Config(com.facebook.buck.config.Config) BuckConfig(com.facebook.buck.cli.BuckConfig) ParserConfig(com.facebook.buck.parser.ParserConfig) PythonBuckConfig(com.facebook.buck.python.PythonBuckConfig) DefaultProjectBuildFileParserFactory(com.facebook.buck.json.DefaultProjectBuildFileParserFactory) DefaultTypeCoercerFactory(com.facebook.buck.rules.coercer.DefaultTypeCoercerFactory) ProjectBuildFileParserFactory(com.facebook.buck.json.ProjectBuildFileParserFactory) DefaultProjectBuildFileParserFactory(com.facebook.buck.json.DefaultProjectBuildFileParserFactory) ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) BuckConfig(com.facebook.buck.cli.BuckConfig) PythonBuckConfig(com.facebook.buck.python.PythonBuckConfig) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) TestConsole(com.facebook.buck.testutil.TestConsole) ParserConfig(com.facebook.buck.parser.ParserConfig) Test(org.junit.Test)

Example 15 with ExecutableFinder

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

the class ParserConfigTest method whenParserPythonDoesNotExistThenItIsNotUsed.

@Test(expected = HumanReadableException.class)
public void whenParserPythonDoesNotExistThenItIsNotUsed() throws IOException {
    String invalidPath = temporaryFolder.getRoot().toAbsolutePath() + "DoesNotExist";
    ParserConfig parserConfig = FakeBuckConfig.builder().setSections(ImmutableMap.of("parser", ImmutableMap.of("python_interpreter", invalidPath))).build().getView(ParserConfig.class);
    parserConfig.getPythonInterpreter(new ExecutableFinder());
    fail("Should throw exception as python config is invalid.");
}
Also used : ExecutableFinder(com.facebook.buck.io.ExecutableFinder) 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