use of com.facebook.buck.util.Console in project buck by facebook.
the class WorkerProcessTest method testDoesNotBlockOnLargeStderr.
@Test(timeout = 20 * 1000)
public void testDoesNotBlockOnLargeStderr() throws IOException {
ProjectWorkspace workspace = TestDataHelper.createProjectWorkspaceForScenario(this, "worker_process", temporaryPaths);
workspace.setUp();
ProjectFilesystem projectFilesystem = new ProjectFilesystem(workspace.getDestPath());
Console console = new Console(Verbosity.ALL, System.out, System.err, Ansi.withoutTty());
String script;
if (Platform.detect() == Platform.WINDOWS) {
script = workspace.getDestPath().resolve("script.bat").toString();
} else {
script = "./script.py";
}
WorkerProcess workerProcess = new WorkerProcess(new DefaultProcessExecutor(console), ProcessExecutorParams.builder().setCommand(ImmutableList.of(script)).setDirectory(workspace.getDestPath()).build(), projectFilesystem, temporaryPaths.newFolder());
try {
workerProcess.ensureLaunchAndHandshake();
fail("Handshake should have failed");
} catch (HumanReadableException e) {
// Check that all of the process's stderr was reported.
assertThat(e.getMessage().length(), is(greaterThan(1024 * 1024)));
}
}
use of com.facebook.buck.util.Console in project buck by facebook.
the class ServerStatusCommand method runWithoutHelp.
@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
ImmutableMap.Builder<String, Object> builder = ImmutableMap.builder();
if (isShowHttpserverPort()) {
int port = -1;
Optional<WebServer> webServer = params.getWebServer();
if (webServer.isPresent()) {
port = webServer.get().getPort().orElse(port);
}
builder.put("http.port", port);
}
ImmutableMap<String, Object> values = builder.build();
Console console = params.getConsole();
if (isPrintJson()) {
console.getStdOut().println(params.getObjectMapper().writeValueAsString(values));
} else {
for (Map.Entry<String, Object> entry : values.entrySet()) {
console.getStdOut().printf("%s=%s%n", entry.getKey(), entry.getValue());
}
}
return 0;
}
use of com.facebook.buck.util.Console in project buck by facebook.
the class SuggestCommand method runWithoutHelp.
/**
* Normalizes the sole build target argument and partitions it using a
* {@link FineGrainedJavaDependencySuggester}.
*/
@Override
public int runWithoutHelp(final CommandRunnerParams params) throws IOException, InterruptedException {
final Console console = params.getConsole();
if (arguments.size() != 1) {
console.printErrorText("Must specify exactly one argument to 'buck suggest'.");
return 1;
}
String targetToBreakDown = Iterables.getOnlyElement(arguments);
final String fullyQualifiedTarget = Iterables.getOnlyElement(getCommandLineBuildTargetNormalizer(params.getBuckConfig()).normalize(targetToBreakDown));
JavaBuildGraphProcessor.Processor processor = (graph, javaDepsFinder, executorService) -> {
BuildTarget buildTarget = params.getBuckConfig().getBuildTargetForFullyQualifiedTarget(fullyQualifiedTarget);
FineGrainedJavaDependencySuggester suggester = new FineGrainedJavaDependencySuggester(buildTarget, graph, javaDepsFinder, console);
suggester.suggestRefactoring();
};
try {
JavaBuildGraphProcessor.run(params, this, processor);
} catch (JavaBuildGraphProcessor.ExitCodeException e) {
return e.exitCode;
}
return 0;
}
use of com.facebook.buck.util.Console in project buck by facebook.
the class DistBuildRunCommand method runWithoutHelp.
@Override
public int runWithoutHelp(CommandRunnerParams params) throws IOException, InterruptedException {
Stopwatch stopwatch = Stopwatch.createStarted();
Console console = params.getConsole();
try (DistBuildService service = DistBuildFactory.newDistBuildService(params)) {
Pair<BuildJobState, String> jobStateAndBuildName = getBuildJobStateAndBuildName(params.getCell().getFilesystem(), console, service);
BuildJobState jobState = jobStateAndBuildName.getFirst();
String buildName = jobStateAndBuildName.getSecond();
console.getStdOut().println(String.format("BuildJob depends on a total of [%d] input deps.", jobState.getFileHashesSize()));
try (CommandThreadManager pool = new CommandThreadManager(getClass().getName(), getConcurrencyLimit(params.getBuckConfig()))) {
DistBuildSlaveExecutor distBuildExecutor = DistBuildFactory.createDistBuildExecutor(jobState, params, pool.getExecutor(), service, Preconditions.checkNotNull(distBuildMode), coordinatorPort, getStampedeIdOptional(), getGlobalCacheDirOptional());
int returnCode = distBuildExecutor.buildAndReturnExitCode();
if (returnCode == 0) {
console.printSuccess(String.format("Successfully ran distributed build [%s] in [%d millis].", buildName, stopwatch.elapsed(TimeUnit.MILLISECONDS)));
} else {
console.printErrorText("Failed distributed build [%s] in [%d millis].", buildName, stopwatch.elapsed(TimeUnit.MILLISECONDS));
}
return returnCode;
}
}
}
use of com.facebook.buck.util.Console in project buck by facebook.
the class Project method processJsonConfig.
private ExitCodeAndOutput processJsonConfig(File jsonTempFile, boolean generateMinimalProject) throws IOException, InterruptedException {
ImmutableList.Builder<String> argsBuilder = ImmutableList.<String>builder().add(pythonInterpreter).add(PATH_TO_INTELLIJ_PY).add(jsonTempFile.getAbsolutePath());
if (generateMinimalProject) {
argsBuilder.add("--generate_minimum_project");
}
if (turnOffAutoSourceGeneration) {
argsBuilder.add("--disable_android_auto_generation_setting");
}
final ImmutableList<String> args = argsBuilder.build();
ShellStep command = new ShellStep(projectFilesystem.getRootPath()) {
@Override
public String getShortName() {
return "python";
}
@Override
protected ImmutableList<String> getShellCommandInternal(ExecutionContext context) {
return args;
}
};
Console console = executionContext.getConsole();
Console childConsole = new Console(Verbosity.SILENT, console.getStdOut(), console.getStdErr(), Ansi.withoutTty());
int exitCode;
try (ExecutionContext childContext = ExecutionContext.builder().from(executionContext).setConsole(childConsole).setExecutors(executionContext.getExecutors()).build()) {
exitCode = command.execute(childContext).getExitCode();
}
return new ExitCodeAndOutput(exitCode, command.getStdout(), command.getStderr());
}
Aggregations