use of com.facebook.buck.io.ExecutableFinder in project buck by facebook.
the class PythonBuckConfigTest method testPathToPexExecuterUsesConfigSetting.
@Test
public void testPathToPexExecuterUsesConfigSetting() throws IOException {
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
Path projectDir = Files.createTempDirectory("project");
Path pexExecuter = Paths.get("pex-exectuter");
ProjectFilesystem projectFilesystem = new FakeProjectFilesystem(new FakeClock(0), projectDir, ImmutableSet.of(pexExecuter));
Files.createFile(projectFilesystem.resolve(pexExecuter));
assertTrue("Should be able to set file executable", projectFilesystem.resolve(pexExecuter).toFile().setExecutable(true));
PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().setSections(ImmutableMap.of("python", ImmutableMap.of("path_to_pex_executer", pexExecuter.toString()))).setFilesystem(projectFilesystem).build(), new ExecutableFinder());
assertThat(config.getPexExecutor(resolver).get().getCommandPrefix(pathResolver), Matchers.contains(pexExecuter.toString()));
}
use of com.facebook.buck.io.ExecutableFinder in project buck by facebook.
the class PythonBuckConfigTest method whenPythonOnPathIsExecutableFileThenItIsUsed.
@Test
public void whenPythonOnPathIsExecutableFileThenItIsUsed() throws IOException {
temporaryFolder.newExecutableFile("python");
PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().setEnvironment(ImmutableMap.<String, String>builder().put("PATH", temporaryFolder.getRoot().toAbsolutePath().toString()).put("PATHEXT", "").build()).build(), new ExecutableFinder());
config.getPythonInterpreter();
}
use of com.facebook.buck.io.ExecutableFinder in project buck by facebook.
the class CxxPythonExtensionDescriptionTest method platformDepsSeparateLinkage.
@Test
public void platformDepsSeparateLinkage() throws Exception {
PythonBuckConfig pythonBuckConfig = new PythonBuckConfig(FakeBuckConfig.builder().build(), new ExecutableFinder());
FlavorDomain<PythonPlatform> pythonPlatforms = FlavorDomain.of("Python Platform", PY2, PY3);
CxxLibraryBuilder depBuilder = new CxxLibraryBuilder(BuildTargetFactory.newInstance("//:dep")).setSrcs(ImmutableSortedSet.of(SourceWithFlags.of(new FakeSourcePath("test.c"))));
CxxPythonExtensionBuilder extensionBuilder = new CxxPythonExtensionBuilder(BuildTargetFactory.newInstance("//:rule"), pythonPlatforms, new CxxBuckConfig(FakeBuckConfig.builder().build()), CxxTestBuilder.createDefaultPlatforms()).setPlatformDeps(PatternMatchedCollection.<ImmutableSortedSet<BuildTarget>>builder().add(Pattern.compile(PY2.getFlavor().toString()), ImmutableSortedSet.of(depBuilder.getTarget())).build());
PythonBinaryBuilder binary2Builder = new PythonBinaryBuilder(BuildTargetFactory.newInstance("//:bin2"), pythonBuckConfig, pythonPlatforms, CxxTestBuilder.createDefaultPlatform(), CxxTestBuilder.createDefaultPlatforms()).setMainModule("test").setPlatform(PY2.getFlavor().toString()).setDeps(ImmutableSortedSet.of(extensionBuilder.getTarget()));
PythonBinaryBuilder binary3Builder = new PythonBinaryBuilder(BuildTargetFactory.newInstance("//:bin3"), pythonBuckConfig, pythonPlatforms, CxxTestBuilder.createDefaultPlatform(), CxxTestBuilder.createDefaultPlatforms()).setMainModule("test").setPlatform(PY3.getFlavor().toString()).setDeps(ImmutableSortedSet.of(extensionBuilder.getTarget()));
BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(depBuilder.build(), extensionBuilder.build(), binary2Builder.build()), new DefaultTargetNodeToBuildRuleTransformer());
depBuilder.build(resolver);
extensionBuilder.build(resolver);
PythonBinary binary2 = binary2Builder.build(resolver);
PythonBinary binary3 = binary3Builder.build(resolver);
assertThat(binary2.getComponents().getNativeLibraries().keySet(), Matchers.contains(Paths.get("libdep.so")));
assertThat(binary3.getComponents().getNativeLibraries().keySet(), Matchers.not(Matchers.contains(Paths.get("libdep.so"))));
}
use of com.facebook.buck.io.ExecutableFinder in project buck by facebook.
the class PythonTestIntegrationTest method assumePythonVersionIsAtLeast.
private void assumePythonVersionIsAtLeast(String expectedVersion, String message) throws InterruptedException {
PythonVersion actualVersion = new PythonBuckConfig(FakeBuckConfig.builder().build(), new ExecutableFinder()).getPythonEnvironment(new DefaultProcessExecutor(new TestConsole())).getPythonVersion();
assumeTrue(String.format("Needs at least Python-%s, but found Python-%s: %s", expectedVersion, actualVersion, message), new VersionStringComparator().compare(actualVersion.getVersionString(), expectedVersion) >= 0);
}
use of com.facebook.buck.io.ExecutableFinder in project buck by facebook.
the class KotlinBuckConfig method getKotlinHome.
private Path getKotlinHome() {
if (kotlinHome != null) {
return kotlinHome;
}
try {
// Check the buck configuration for a specified kotlin compliler
Optional<String> value = delegate.getValue(SECTION, "compiler");
boolean isAbsolute = (value.isPresent() && Paths.get(value.get()).isAbsolute());
Optional<Path> compilerPath = delegate.getPath(SECTION, "compiler", !isAbsolute);
if (compilerPath.isPresent()) {
if (Files.isExecutable(compilerPath.get())) {
kotlinHome = compilerPath.get().toRealPath().getParent().normalize();
if (kotlinHome != null && kotlinHome.endsWith(Paths.get("bin"))) {
kotlinHome = kotlinHome.getParent().normalize();
}
return kotlinHome;
} else {
throw new HumanReadableException("Could not deduce kotlin home directory from path " + compilerPath.toString());
}
} else {
// If the KOTLIN_HOME environment variable is specified we trust it
String home = delegate.getEnvironment().get("KOTLIN_HOME");
if (home != null) {
kotlinHome = Paths.get(home).normalize();
return kotlinHome;
} else {
// Lastly, we try to resolve from the system PATH
Optional<Path> compiler = new ExecutableFinder().getOptionalExecutable(DEFAULT_KOTLIN_COMPILER, delegate.getEnvironment());
if (compiler.isPresent()) {
kotlinHome = compiler.get().toRealPath().getParent().normalize();
if (kotlinHome != null && kotlinHome.endsWith(Paths.get("bin"))) {
kotlinHome = kotlinHome.getParent().normalize();
}
return kotlinHome;
} else {
throw new HumanReadableException("Could not resolve kotlin home directory, Consider setting KOTLIN_HOME.");
}
}
}
} catch (IOException io) {
throw new HumanReadableException("Could not resolve kotlin home directory, Consider setting KOTLIN_HOME.", io);
}
}
Aggregations