Search in sources :

Example 6 with Console

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)));
    }
}
Also used : ProjectWorkspace(com.facebook.buck.testutil.integration.ProjectWorkspace) DefaultProcessExecutor(com.facebook.buck.util.DefaultProcessExecutor) HumanReadableException(com.facebook.buck.util.HumanReadableException) Console(com.facebook.buck.util.Console) FakeProjectFilesystem(com.facebook.buck.testutil.FakeProjectFilesystem) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Test(org.junit.Test)

Example 7 with Console

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;
}
Also used : WebServer(com.facebook.buck.httpserver.WebServer) Console(com.facebook.buck.util.Console) ImmutableMap(com.google.common.collect.ImmutableMap) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 8 with Console

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;
}
Also used : Iterables(com.google.common.collect.Iterables) List(java.util.List) Lists(com.google.common.collect.Lists) Argument(org.kohsuke.args4j.Argument) IOException(java.io.IOException) Console(com.facebook.buck.util.Console) BuildTarget(com.facebook.buck.model.BuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) Console(com.facebook.buck.util.Console)

Example 9 with Console

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;
        }
    }
}
Also used : Stopwatch(com.google.common.base.Stopwatch) Console(com.facebook.buck.util.Console) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) DistBuildService(com.facebook.buck.distributed.DistBuildService) DistBuildSlaveExecutor(com.facebook.buck.distributed.DistBuildSlaveExecutor)

Example 10 with Console

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());
}
Also used : ExecutionContext(com.facebook.buck.step.ExecutionContext) ImmutableList(com.google.common.collect.ImmutableList) ShellStep(com.facebook.buck.shell.ShellStep) Console(com.facebook.buck.util.Console)

Aggregations

Console (com.facebook.buck.util.Console)12 Test (org.junit.Test)3 DistBuildService (com.facebook.buck.distributed.DistBuildService)2 BuckEventBus (com.facebook.buck.event.BuckEventBus)2 WebServer (com.facebook.buck.httpserver.WebServer)2 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)2 TestConsole (com.facebook.buck.testutil.TestConsole)2 ProjectWorkspace (com.facebook.buck.testutil.integration.ProjectWorkspace)2 DefaultProcessExecutor (com.facebook.buck.util.DefaultProcessExecutor)2 HumanReadableException (com.facebook.buck.util.HumanReadableException)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)2 ImmutableList (com.google.common.collect.ImmutableList)2 ImmutableMap (com.google.common.collect.ImmutableMap)2 IOException (java.io.IOException)2 Map (java.util.Map)2 IDevice (com.android.ddmlib.IDevice)1 AndroidBuckConfig (com.facebook.buck.android.AndroidBuckConfig)1 AndroidDirectoryResolver (com.facebook.buck.android.AndroidDirectoryResolver)1 AndroidLibraryDescription (com.facebook.buck.android.AndroidLibraryDescription)1 AndroidPlatformTarget (com.facebook.buck.android.AndroidPlatformTarget)1