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());
}
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());
}
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();
}
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);
}
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.");
}
Aggregations