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())))));
}
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));
}
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);
}
}
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);
}
}
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));
}
Aggregations