Search in sources :

Example 16 with Tool

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

the class ExecutableMacroExpanderTest method testBuildTimeDependencies.

@Test
public void testBuildTimeDependencies() throws Exception {
    ProjectFilesystem filesystem = new FakeProjectFilesystem();
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    SourcePathResolver pathResolver = new SourcePathResolver(new SourcePathRuleFinder(ruleResolver));
    final BuildRule dep1 = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep1")).setOut("arg1").build(ruleResolver, filesystem);
    final BuildRule dep2 = GenruleBuilder.newGenruleBuilder(BuildTargetFactory.newInstance("//:dep2")).setOut("arg2").build(ruleResolver, filesystem);
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
    ruleResolver.addToIndex(new NoopBinaryBuildRule(params) {

        @Override
        public Tool getExecutableCommand() {
            return new CommandTool.Builder().addArg(SourcePathArg.of(dep1.getSourcePathToOutput())).addArg(SourcePathArg.of(dep2.getSourcePathToOutput())).build();
        }
    });
    // Verify that the correct cmd was created.
    ExecutableMacroExpander expander = new ExecutableMacroExpander();
    assertThat(expander.extractBuildTimeDeps(target, createCellRoots(filesystem), ruleResolver, ImmutableList.of("//:rule")), Matchers.containsInAnyOrder(dep1, dep2));
    assertThat(expander.expand(target, createCellRoots(filesystem), ruleResolver, ImmutableList.of("//:rule")), Matchers.equalTo(String.format("%s %s", pathResolver.getAbsolutePath(Preconditions.checkNotNull(dep1.getSourcePathToOutput())), pathResolver.getAbsolutePath(Preconditions.checkNotNull(dep2.getSourcePathToOutput())))));
}
Also used : FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) JavaBinaryRuleBuilder(com.facebook.buck.jvm.java.JavaBinaryRuleBuilder) JavaLibraryBuilder(com.facebook.buck.jvm.java.JavaLibraryBuilder) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) NoopBuildRule(com.facebook.buck.rules.NoopBuildRule) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) Tool(com.facebook.buck.rules.Tool) CommandTool(com.facebook.buck.rules.CommandTool) Test(org.junit.Test)

Example 17 with Tool

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

the class ExecutableMacroExpanderTest method extractRuleKeyAppendable.

@Test
public void extractRuleKeyAppendable() throws MacroException {
    BuildRuleResolver ruleResolver = new BuildRuleResolver(TargetGraph.EMPTY, new DefaultTargetNodeToBuildRuleTransformer());
    BuildTarget target = BuildTargetFactory.newInstance("//:rule");
    BuildRuleParams params = new FakeBuildRuleParamsBuilder(target).build();
    final Tool tool = new CommandTool.Builder().addArg("command").build();
    ruleResolver.addToIndex(new NoopBinaryBuildRule(params) {

        @Override
        public Tool getExecutableCommand() {
            return tool;
        }
    });
    ExecutableMacroExpander expander = new ExecutableMacroExpander();
    assertThat(expander.extractRuleKeyAppendables(target, createCellRoots(params.getProjectFilesystem()), ruleResolver, ImmutableList.of("//:rule")), Matchers.equalTo(tool));
}
Also used : BuildRuleParams(com.facebook.buck.rules.BuildRuleParams) BuildTarget(com.facebook.buck.model.BuildTarget) GenruleBuilder(com.facebook.buck.shell.GenruleBuilder) JavaBinaryRuleBuilder(com.facebook.buck.jvm.java.JavaBinaryRuleBuilder) JavaLibraryBuilder(com.facebook.buck.jvm.java.JavaLibraryBuilder) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) FakeBuildRuleParamsBuilder(com.facebook.buck.rules.FakeBuildRuleParamsBuilder) DefaultTargetNodeToBuildRuleTransformer(com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer) BuildRuleResolver(com.facebook.buck.rules.BuildRuleResolver) Tool(com.facebook.buck.rules.Tool) CommandTool(com.facebook.buck.rules.CommandTool) Test(org.junit.Test)

Example 18 with Tool

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

the class RunCommand method runWithoutHelp.

@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
    if (!hasTargetSpecified()) {
        params.getBuckEventBus().post(ConsoleEvent.severe("No target given to run"));
        params.getBuckEventBus().post(ConsoleEvent.severe("buck run <target> <arg1> <arg2>..."));
        return 1;
    }
    // Make sure the target is built.
    BuildCommand buildCommand = new BuildCommand(ImmutableList.of(getTarget(params.getBuckConfig())));
    int exitCode = buildCommand.runWithoutHelp(params);
    if (exitCode != 0) {
        return exitCode;
    }
    String targetName = getTarget(params.getBuckConfig());
    BuildTarget target = Iterables.getOnlyElement(getBuildTargets(params.getCell().getCellPathResolver(), ImmutableSet.of(targetName)));
    Build build = buildCommand.getBuild();
    BuildRule targetRule;
    try {
        targetRule = build.getRuleResolver().requireRule(target);
    } catch (NoSuchBuildTargetException e) {
        throw new HumanReadableException(e.getHumanReadableErrorMessage());
    }
    BinaryBuildRule binaryBuildRule = null;
    if (targetRule instanceof BinaryBuildRule) {
        binaryBuildRule = (BinaryBuildRule) targetRule;
    }
    if (binaryBuildRule == null) {
        params.getBuckEventBus().post(ConsoleEvent.severe("target " + targetName + " is not a binary rule (only binary rules can be `run`)"));
        return 1;
    }
    // Ideally, we would take fullCommand, disconnect from NailGun, and run the command in the
    // user's shell. Currently, if you use `buck run` with buckd and ctrl-C to kill the command
    // being run, occasionally I get the following error when I try to run `buck run` again:
    //
    //   Daemon is busy, please wait or run "buck kill" to terminate it.
    //
    // Clearly something bad has happened here. If you are using `buck run` to start up a server
    // or some other process that is meant to "run forever," then it's pretty common to do:
    // `buck run`, test server, hit ctrl-C, edit server code, repeat. This should not wedge buckd.
    SourcePathResolver resolver = new SourcePathResolver(new SourcePathRuleFinder(build.getRuleResolver()));
    Tool executable = binaryBuildRule.getExecutableCommand();
    ListeningProcessExecutor processExecutor = new ListeningProcessExecutor();
    ProcessExecutorParams processExecutorParams = ProcessExecutorParams.builder().addAllCommand(executable.getCommandPrefix(resolver)).addAllCommand(getTargetArguments()).setEnvironment(ImmutableMap.<String, String>builder().putAll(params.getEnvironment()).putAll(executable.getEnvironment(resolver)).build()).setDirectory(params.getCell().getFilesystem().getRootPath()).build();
    ForwardingProcessListener processListener = new ForwardingProcessListener(Channels.newChannel(params.getConsole().getStdOut()), Channels.newChannel(params.getConsole().getStdErr()));
    ListeningProcessExecutor.LaunchedProcess process = processExecutor.launchProcess(processExecutorParams, processListener);
    try {
        return processExecutor.waitForProcess(process);
    } finally {
        processExecutor.destroyProcess(process, /* force */
        false);
        processExecutor.waitForProcess(process);
    }
}
Also used : ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) SourcePathResolver(com.facebook.buck.rules.SourcePathResolver) SourcePathRuleFinder(com.facebook.buck.rules.SourcePathRuleFinder) BuildTarget(com.facebook.buck.model.BuildTarget) Build(com.facebook.buck.command.Build) HumanReadableException(com.facebook.buck.util.HumanReadableException) ListeningProcessExecutor(com.facebook.buck.util.ListeningProcessExecutor) NoSuchBuildTargetException(com.facebook.buck.parser.NoSuchBuildTargetException) ForwardingProcessListener(com.facebook.buck.util.ForwardingProcessListener) BinaryBuildRule(com.facebook.buck.rules.BinaryBuildRule) BuildRule(com.facebook.buck.rules.BuildRule) Tool(com.facebook.buck.rules.Tool)

Example 19 with Tool

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

the class DBuckConfigTest method testCompilerNotInPath.

@Test
public void testCompilerNotInPath() throws IOException {
    Path yooserBeen = tmp.newFolder("yooser", "been");
    Path userBean = tmp.newFolder("user", "bean").toRealPath();
    makeFakeExecutable(yooserBeen, "dmd");
    BuckConfig delegate = FakeBuckConfig.builder().setEnvironment(ImmutableMap.of("PATH", userBean.toString())).build();
    DBuckConfig dBuckConfig = new DBuckConfig(delegate);
    String msg = "";
    Tool compiler = null;
    try {
        compiler = dBuckConfig.getDCompiler();
    } catch (HumanReadableException e) {
        msg = e.getMessage();
    }
    // we specify in the test.
    if (delegate.getPlatform() == Platform.MACOS && msg.length() == 0) {
        assertNotNull(compiler);
        assertFalse(toolPath(compiler).contains(userBean.toString()));
        assertFalse(toolPath(compiler).contains(yooserBeen.toString()));
    } else {
        assertEquals("Unable to locate dmd on PATH, or it's not marked as being executable", msg);
    }
}
Also used : Path(java.nio.file.Path) FakeBuckConfig(com.facebook.buck.cli.FakeBuckConfig) BuckConfig(com.facebook.buck.cli.BuckConfig) HumanReadableException(com.facebook.buck.util.HumanReadableException) Tool(com.facebook.buck.rules.Tool) Test(org.junit.Test)

Example 20 with Tool

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

the class JsUtil method workerShellStep.

static WorkerShellStep workerShellStep(WorkerTool worker, String jobArgs, BuildTarget buildTarget, SourcePathResolver sourcePathResolver, ProjectFilesystem projectFilesystem) {
    final Tool tool = worker.getTool();
    final WorkerJobParams params = WorkerJobParams.of(worker.getTempDir(), tool.getCommandPrefix(sourcePathResolver), worker.getArgs(sourcePathResolver), tool.getEnvironment(sourcePathResolver), jobArgs, worker.getMaxWorkers(), worker.isPersistent() ? Optional.of(buildTarget.getCellPath().toString() + buildTarget.toString()) : Optional.empty(), Optional.of(worker.getInstanceKey()));
    return new WorkerShellStep(Optional.of(params), Optional.empty(), Optional.empty(), new WorkerProcessPoolFactory(projectFilesystem));
}
Also used : WorkerJobParams(com.facebook.buck.shell.WorkerJobParams) WorkerProcessPoolFactory(com.facebook.buck.shell.WorkerProcessPoolFactory) WorkerShellStep(com.facebook.buck.shell.WorkerShellStep) Tool(com.facebook.buck.rules.Tool) WorkerTool(com.facebook.buck.shell.WorkerTool)

Aggregations

Tool (com.facebook.buck.rules.Tool)30 BuildTarget (com.facebook.buck.model.BuildTarget)14 SourcePathRuleFinder (com.facebook.buck.rules.SourcePathRuleFinder)12 Test (org.junit.Test)12 CommandTool (com.facebook.buck.rules.CommandTool)11 BuildRule (com.facebook.buck.rules.BuildRule)10 BuildRuleResolver (com.facebook.buck.rules.BuildRuleResolver)9 SourcePathResolver (com.facebook.buck.rules.SourcePathResolver)9 SourcePath (com.facebook.buck.rules.SourcePath)8 Path (java.nio.file.Path)8 BuildRuleParams (com.facebook.buck.rules.BuildRuleParams)7 DefaultTargetNodeToBuildRuleTransformer (com.facebook.buck.rules.DefaultTargetNodeToBuildRuleTransformer)6 VersionedTool (com.facebook.buck.rules.VersionedTool)5 ImmutableList (com.google.common.collect.ImmutableList)5 CxxPlatform (com.facebook.buck.cxx.CxxPlatform)4 FakeBuildRuleParamsBuilder (com.facebook.buck.rules.FakeBuildRuleParamsBuilder)4 FakeSourcePath (com.facebook.buck.rules.FakeSourcePath)4 HashedFileTool (com.facebook.buck.rules.HashedFileTool)4 HumanReadableException (com.facebook.buck.util.HumanReadableException)4 NoSuchBuildTargetException (com.facebook.buck.parser.NoSuchBuildTargetException)3