use of com.facebook.buck.rules.BinaryBuildRule in project buck by facebook.
the class GoDescriptors method getTestMainGenerator.
static Tool getTestMainGenerator(GoBuckConfig goBuckConfig, BuildRuleParams sourceParams, BuildRuleResolver resolver) throws NoSuchBuildTargetException {
Optional<Tool> configTool = goBuckConfig.getGoTestMainGenerator(resolver);
if (configTool.isPresent()) {
return configTool.get();
}
// TODO(mikekap): Make a single test main gen, rather than one per test. The generator itself
// doesn't vary per test.
BuildTarget generatorTarget = sourceParams.getBuildTarget().withFlavors(InternalFlavor.of("make-test-main-gen"));
Optional<BuildRule> generator = resolver.getRuleOptional(generatorTarget);
if (generator.isPresent()) {
return ((BinaryBuildRule) generator.get()).getExecutableCommand();
}
BuildTarget generatorSourceTarget = sourceParams.getBuildTarget().withAppendedFlavors(InternalFlavor.of("test-main-gen-source"));
WriteFile writeFile = resolver.addToIndex(new WriteFile(sourceParams.withBuildTarget(generatorSourceTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of())), extractTestMainGenerator(), BuildTargets.getGenPath(sourceParams.getProjectFilesystem(), generatorSourceTarget, "%s/main.go"), /* executable */
false));
GoBinary binary = resolver.addToIndex(createGoBinaryRule(sourceParams.withBuildTarget(generatorTarget).copyReplacingDeclaredAndExtraDeps(Suppliers.ofInstance(ImmutableSortedSet.of()), Suppliers.ofInstance(ImmutableSortedSet.of(writeFile))), resolver, goBuckConfig, ImmutableSet.of(writeFile.getSourcePathToOutput()), ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), goBuckConfig.getDefaultPlatform()));
return binary.getExecutableCommand();
}
use of com.facebook.buck.rules.BinaryBuildRule in project buck by facebook.
the class AppleCxxPlatformsTest method buckTargetIsUsedWhenBuildTargetIsSpecified.
@Test
public void buckTargetIsUsedWhenBuildTargetIsSpecified() {
AppleCxxPlatform appleCxxPlatform = buildAppleCxxPlatform(temp.getRoot(), FakeBuckConfig.builder().setSections("[apple]", "codesign = //foo:bar").build());
BuildTarget buildTarget = BuildTargetFactory.newInstance("//foo:bar");
BinaryBuildRule buildRule = EasyMock.createMock(BinaryBuildRule.class);
Tool codesign = EasyMock.createMock(Tool.class);
EasyMock.expect(buildRule.getExecutableCommand()).andReturn(codesign);
BuildRuleResolver buildRuleResolver = EasyMock.createMock(BuildRuleResolver.class);
EasyMock.expect(buildRuleResolver.getRuleOptional(buildTarget)).andReturn(Optional.of(buildRule));
EasyMock.replay(buildRule, buildRuleResolver);
assertThat(appleCxxPlatform.getCodesignProvider().resolve(buildRuleResolver), is(codesign));
}
use of com.facebook.buck.rules.BinaryBuildRule 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.BinaryBuildRule in project buck by facebook.
the class WorkerToolDescription method createBuildRule.
@Override
public <A extends Arg> BuildRule createBuildRule(TargetGraph targetGraph, final BuildRuleParams params, final BuildRuleResolver resolver, A args) throws NoSuchBuildTargetException {
BuildRule rule = resolver.requireRule(args.exe);
if (!(rule instanceof BinaryBuildRule)) {
throw new HumanReadableException("The 'exe' argument of %s, %s, needs to correspond to a " + "binary rule, such as sh_binary().", params.getBuildTarget(), args.exe.getFullyQualifiedName());
}
Function<String, com.facebook.buck.rules.args.Arg> toArg = MacroArg.toMacroArgFunction(MACRO_HANDLER, params.getBuildTarget(), params.getCellRoots(), resolver);
final ImmutableList<com.facebook.buck.rules.args.Arg> workerToolArgs = args.getStartupArgs().stream().map(toArg::apply).collect(MoreCollectors.toImmutableList());
ImmutableMap<String, String> expandedEnv = ImmutableMap.copyOf(FluentIterable.from(args.env.entrySet()).transform(input -> {
try {
return Maps.immutableEntry(input.getKey(), MACRO_HANDLER.expand(params.getBuildTarget(), params.getCellRoots(), resolver, input.getValue()));
} catch (MacroException e) {
throw new HumanReadableException(e, "%s: %s", params.getBuildTarget(), e.getMessage());
}
}));
int maxWorkers;
if (args.maxWorkers.isPresent()) {
// negative or zero: unlimited number of worker processes
maxWorkers = args.maxWorkers.get() < 1 ? Integer.MAX_VALUE : args.maxWorkers.get();
} else {
// default is 1 worker process (for backwards compatibility)
maxWorkers = 1;
}
return new DefaultWorkerTool(params, (BinaryBuildRule) rule, workerToolArgs, expandedEnv, maxWorkers, args.persistent.orElse(buckConfig.getBooleanValue(CONFIG_SECTION, CONFIG_PERSISTENT_KEY, false)));
}
Aggregations