Search in sources :

Example 1 with ShBinaryBuilder

use of com.facebook.buck.shell.ShBinaryBuilder in project buck by facebook.

the class PythonTestDescriptionTest method pexExecutorRuleIsAddedToParseTimeDeps.

@Test
public void pexExecutorRuleIsAddedToParseTimeDeps() throws Exception {
    ShBinaryBuilder pexExecutorBuilder = new ShBinaryBuilder(BuildTargetFactory.newInstance("//:pex_executor")).setMain(new FakeSourcePath("run.sh"));
    PythonTestBuilder builder = new PythonTestBuilder(BuildTargetFactory.newInstance("//:bin"), new PythonBuckConfig(FakeBuckConfig.builder().setSections(ImmutableMap.of("python", ImmutableMap.of("path_to_pex_executer", pexExecutorBuilder.getTarget().toString()))).build(), new AlwaysFoundExecutableFinder()), PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS);
    builder.setPackageStyle(PythonBuckConfig.PackageStyle.STANDALONE);
    assertThat(builder.build().getExtraDeps(), Matchers.hasItem(pexExecutorBuilder.getTarget()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ShBinaryBuilder(com.facebook.buck.shell.ShBinaryBuilder) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 2 with ShBinaryBuilder

use of com.facebook.buck.shell.ShBinaryBuilder in project buck by facebook.

the class WorkerMacroArgTest method testWorkerMacroArgConstruction.

@Test
public void testWorkerMacroArgConstruction() throws MacroException, NoSuchBuildTargetException {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(resolver));
    BuildRule shBinaryRule = new ShBinaryBuilder(BuildTargetFactory.newInstance("//:my_exe")).setMain(new FakeSourcePath("bin/exe")).build(resolver);
    String startupArgs = "startupargs";
    Integer maxWorkers = 5;
    WorkerToolBuilder.newWorkerToolBuilder(BuildTargetFactory.newInstance("//:worker_rule")).setExe(shBinaryRule.getBuildTarget()).setArgs(startupArgs).setMaxWorkers(maxWorkers).build(resolver);
    MacroHandler macroHandler = new MacroHandler(ImmutableMap.of("worker", new WorkerMacroExpander()));
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    String jobArgs = "jobargs";
    WorkerMacroArg arg = new WorkerMacroArg(macroHandler, target, TestCellBuilder.createCellRoots(filesystem), resolver, "$(worker //:worker_rule) " + jobArgs);
    assertThat(arg.getJobArgs(), Matchers.equalTo(jobArgs));
    assertThat(arg.getStartupArgs(pathResolver), Matchers.equalTo(startupArgs));
    assertThat(arg.getMaxWorkers(), Matchers.equalTo(maxWorkers));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) MacroHandler(com.facebook.buck.rules.macros.MacroHandler) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildTarget(com.facebook.buck.model.BuildTarget) FakeBuildRule(com.facebook.buck.rules.FakeBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) ShBinaryBuilder(com.facebook.buck.shell.ShBinaryBuilder) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) WorkerMacroExpander(com.facebook.buck.rules.macros.WorkerMacroExpander) Test(org.junit.Test)

Example 3 with ShBinaryBuilder

use of com.facebook.buck.shell.ShBinaryBuilder in project buck by facebook.

the class PythonBinaryDescriptionTest method pexExecutorRuleIsAddedToParseTimeDeps.

@Test
public void pexExecutorRuleIsAddedToParseTimeDeps() throws Exception {
    ShBinaryBuilder pexExecutorBuilder = new ShBinaryBuilder(BuildTargetFactory.newInstance("//:pex_executor")).setMain(new FakeSourcePath("run.sh"));
    PythonBinaryBuilder builder = new PythonBinaryBuilder(BuildTargetFactory.newInstance("//:bin"), new PythonBuckConfig(FakeBuckConfig.builder().setSections(ImmutableMap.of("python", ImmutableMap.of("path_to_pex_executer", pexExecutorBuilder.getTarget().toString()))).build(), new AlwaysFoundExecutableFinder()), PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS);
    builder.setMainModule("main").setPackageStyle(PythonBuckConfig.PackageStyle.STANDALONE);
    assertThat(builder.build().getExtraDeps(), Matchers.hasItem(pexExecutorBuilder.getTarget()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ShBinaryBuilder(com.facebook.buck.shell.ShBinaryBuilder) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Example 4 with ShBinaryBuilder

use of com.facebook.buck.shell.ShBinaryBuilder in project buck by facebook.

the class PythonBinaryDescriptionTest method pexToolBuilderAddedToRuntimeDeps.

@Test
public void pexToolBuilderAddedToRuntimeDeps() throws Exception {
    BuildRuleResolver resolver = new BuildRuleResolver(TargetGraphFactory.newInstance(), new DefaultTargetNodeToBuildRuleTransformer());
    ShBinary pyTool = new ShBinaryBuilder(BuildTargetFactory.newInstance("//:py_tool")).setMain(new FakeSourcePath("run.sh")).build(resolver);
    PythonBuckConfig config = new PythonBuckConfig(FakeBuckConfig.builder().build(), new AlwaysFoundExecutableFinder()) {

        @Override
        public Optional<Tool> getPexExecutor(BuildRuleResolver resolver) {
            return Optional.of(pyTool.getExecutableCommand());
        }
    };
    PythonBinary standaloneBinary = new PythonBinaryBuilder(BuildTargetFactory.newInstance("//:bin"), config, PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS).setMainModule("hello").setPackageStyle(PythonBuckConfig.PackageStyle.STANDALONE).build(resolver);
    assertThat(standaloneBinary.getRuntimeDeps().collect(MoreCollectors.toImmutableSet()), Matchers.hasItem(pyTool.getBuildTarget()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ShBinary(com.facebook.buck.shell.ShBinary) ShBinaryBuilder(com.facebook.buck.shell.ShBinaryBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) 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 5 with ShBinaryBuilder

use of com.facebook.buck.shell.ShBinaryBuilder in project buck by facebook.

the class PythonTestDescriptionTest method pexExecutorIsAddedToTestRuntimeDeps.

@Test
public void pexExecutorIsAddedToTestRuntimeDeps() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    ShBinaryBuilder pexExecutorBuilder = new ShBinaryBuilder(BuildTargetFactory.newInstance("//:pex_executor")).setMain(new FakeSourcePath("run.sh"));
    PythonTestBuilder builder = new PythonTestBuilder(BuildTargetFactory.newInstance("//:bin"), new PythonBuckConfig(FakeBuckConfig.builder().setSections(ImmutableMap.of("python", ImmutableMap.of("path_to_pex_executer", pexExecutorBuilder.getTarget().toString()))).build(), new AlwaysFoundExecutableFinder()), PythonTestUtils.PYTHON_PLATFORMS, CxxPlatformUtils.DEFAULT_PLATFORM, CxxPlatformUtils.DEFAULT_PLATFORMS);
    builder.setPackageStyle(PythonBuckConfig.PackageStyle.STANDALONE);
    TargetGraph targetGraph = TargetGraphFactory.newInstance(pexExecutorBuilder.build(), builder.build());
    BuildRuleResolver resolver = new BuildRuleResolver(targetGraph, new DefaultTargetNodeToBuildRuleTransformer());
    ShBinary pexExecutor = pexExecutorBuilder.build(resolver);
    PythonTest binary = builder.build(resolver, filesystem, targetGraph);
    assertThat(binary.getRuntimeDeps().collect(MoreCollectors.toImmutableSet()), Matchers.hasItem(pexExecutor.getBuildTarget()));
}
Also used : FakeSourcePath(com.facebook.buck.rules.FakeSourcePath) ShBinary(com.facebook.buck.shell.ShBinary) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) AllExistingProjectFilesystem(com.facebook.buck.testutil.AllExistingProjectFilesystem) ShBinaryBuilder(com.facebook.buck.shell.ShBinaryBuilder) TargetGraph(com.facebook.buck.rules.TargetGraph) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) AlwaysFoundExecutableFinder(com.facebook.buck.io.AlwaysFoundExecutableFinder) Test(org.junit.Test)

Aggregations

FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)5 ShBinaryBuilder (com.facebook.buck.shell.ShBinaryBuilder)5 Test (org.junit.Test)5 AlwaysFoundExecutableFinder (com.facebook.buck.io.AlwaysFoundExecutableFinder)4 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)3 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)3 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)2 ShBinary (com.facebook.buck.shell.ShBinary)2 FakeProjectFilesystem (com.facebook.buck.testutil.FakeProjectFilesystem)2 BuildTarget (com.facebook.buck.model.BuildTarget)1 BuildRule (com.facebook.buck.rules.BuildRule)1 CommandTool (com.facebook.buck.rules.CommandTool)1 FakeBuildRule (com.facebook.buck.rules.FakeBuildRule)1 HashedFileTool (com.facebook.buck.rules.HashedFileTool)1 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)1 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)1 TargetGraph (com.facebook.buck.rules.TargetGraph)1 Tool (com.facebook.buck.rules.Tool)1 MacroHandler (com.facebook.buck.rules.macros.MacroHandler)1 WorkerMacroExpander (com.facebook.buck.rules.macros.WorkerMacroExpander)1