Search in sources :

Example 21 with ExecutableFinder

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()));
}
Also used : Path(java.nio.file.Path) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeClock(com.facebook.buck.timing.FakeClock) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Test(org.junit.Test)

Example 22 with ExecutableFinder

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();
}
Also used : ExecutableFinder(com.facebook.buck.io.ExecutableFinder) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 23 with ExecutableFinder

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"))));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) CxxBuckConfig(com.facebook.buck.cxx.CxxBuckConfig) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) PrebuiltCxxLibraryBuilder(com.facebook.buck.cxx.PrebuiltCxxLibraryBuilder) CxxLibraryBuilder(com.facebook.buck.cxx.CxxLibraryBuilder) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Test(org.junit.Test)

Example 24 with ExecutableFinder

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);
}
Also used : ExecutableFinder(com.facebook.buck.io.ExecutableFinder) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) VersionStringComparator(com.facebook.buck.util.VersionStringComparator) TestConsole(com.facebook.buck.testutil.TestConsole)

Example 25 with ExecutableFinder

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);
    }
}
Also used : SourcePath(com.facebook.buck.rules.SourcePath) Path(java.nio.file.Path) ExecutableFinder(com.facebook.buck.io.ExecutableFinder) HumanReadableException(com.facebook.buck.util.HumanReadableException) IOException(java.io.IOException)

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