Search in sources :

Example 16 with HashedFileTool

use of com.facebook.buck.rules.HashedFileTool in project buck by facebook.

the class PythonBinaryDescriptionTest method executableCommandWithPathToPexExecutor.

@Test
public void executableCommandWithPathToPexExecutor() throws Exception {
    BuildTarget target = BuildTargetFactory.newInstance("//foo:bin");
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    final Path executor = Paths.get("executor");
    PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().build(), new AlwaysFoundExecutableFinder()) {

        @Override
        public Optional<Tool> getPexExecutor(BuildRuleResolver resolver) {
            return Optional.of(new HashedFileTool(executor));
        }
    };
    PythonBinaryBuilder builder = new PythonBinaryBuilder(target, config, PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS);
    PythonPackagedBinary binary = (PythonPackagedBinary) builder.setMainModule("main").build(resolver);
    assertThat(binary.getExecutableCommand().getCommandPrefix(pathResolver), Matchers.contains(executor.toString(), pathResolver.getAbsolutePath(binary.getSourcePathToOutput()).toString()));
}
Also used : Path(java.nio.file.Path) SourcePath(com.facebook.buck.rules.SourcePath) FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) BuildTargetSourcePath(com.facebook.buck.rules.BuildTargetSourcePath) DefaultBuildTargetSourcePath(com.facebook.buck.rules.DefaultBuildTargetSourcePath) HashedFileTool(com.facebook.buck.rules.HashedFileTool) BuildTarget(com.facebook.buck.model.BuildTarget) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) HashedFileTool(com.facebook.buck.rules.HashedFileTool) Tool(com.facebook.buck.rules.Tool) CommandTool(com.facebook.buck.rules.CommandTool) Test(org.junit.Test)

Example 17 with HashedFileTool

use of com.facebook.buck.rules.HashedFileTool in project buck by facebook.

the class PythonPackagedBinaryTest method getRuleKeyForModuleLayout.

private RuleKey getRuleKeyForModuleLayout(DefaultRuleKeyFactory ruleKeyFactory, SourcePathRuleFinder ruleFinder, String main, Path mainSrc, String mod1, Path src1, String mod2, Path src2) throws IOException {
    ProjectFilesystem projectFilesystem = new FakeProjectFilesystem();
    // The top-level python binary that lists the above libraries as deps.
    PythonBinary binary = PythonPackagedBinary.from(new FakeBuildRuleParamsBuilder("//:bin").build(), ruleFinder, PythonTestUtils.PYTHON_PLATFORM, PEX, ImmutableList.of(), new HashedFileTool(Paths.get("dummy_path_to_pex_runner")), ".pex", new PythonEnvironment(Paths.get("fake_python"), PythonVersion.of("CPython", "2.7")), "main", PythonPackageComponents.of(ImmutableMap.of(Paths.get(main), new PathSourcePath(projectFilesystem, mainSrc), Paths.get(mod1), new PathSourcePath(projectFilesystem, src1), Paths.get(mod2), new PathSourcePath(projectFilesystem, src2)), ImmutableMap.of(), ImmutableMap.of(), ImmutableSet.of(), Optional.empty()), ImmutableSortedSet.of(), /* cache */
    true, /* legacyOutputPath */
    false);
    // Calculate and return the rule key.
    return ruleKeyFactory.build(binary);
}
Also used : HashedFileTool(com.facebook.buck.rules.HashedFileTool) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) PathSourcePath(com.facebook.buck.rules.PathSourcePath) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder)

Aggregations

HashedFileTool (com.facebook.buck.rules.HashedFileTool)17 Path (java.nio.file.Path)11 BuildTarget (com.facebook.buck.model.BuildTarget)7 ConstantToolProvider (com.facebook.buck.rules.ConstantToolProvider)7 HumanReadableException (com.facebook.buck.util.HumanReadableException)6 Test (org.junit.Test)6 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)5 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)5 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)5 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)5 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)5 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)5 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)4 ExecutableFinder (com.facebook.buck.io.ExecutableFinder)3 CommandTool (com.facebook.buck.rules.CommandTool)3 RuleKey (com.facebook.buck.rules.RuleKey)3 ToolProvider (com.facebook.buck.rules.ToolProvider)3 DefaultRuleKeyFactory (com.facebook.buck.rules.keys.DefaultRuleKeyFactory)3 FakeFileHashCache (com.facebook.buck.testutil.FakeFileHashCache)3 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)2