Search in sources :

Example 1 with InputStreamConsumer

use of com.facebook.buck.util.InputStreamConsumer in project buck by facebook.

the class ProjectBuildFileParser method init.

/**
   * Initialize the parser, starting buck.py.
   */
private void init() throws IOException {
    projectBuildFileParseEventStarted = new ProjectBuildFileParseEvents.Started();
    buckEventBus.post(projectBuildFileParseEventStarted);
    try (SimplePerfEvent.Scope scope = SimplePerfEvent.scope(buckEventBus, PerfEventId.of("ParserInit"))) {
        ImmutableMap.Builder<String, String> pythonEnvironmentBuilder = ImmutableMap.builder();
        // Strip out PYTHONPATH. buck.py manually sets this to include only nailgun. We don't want
        // to inject nailgun into the parser's PYTHONPATH, so strip that value out.
        // If we wanted to pass on some environmental PYTHONPATH, we would have to do some actual
        // merging of this and the BuckConfig's python module search path.
        pythonEnvironmentBuilder.putAll(Maps.filterKeys(environment, k -> !PYTHONPATH_ENV_VAR_NAME.equals(k)));
        if (options.getPythonModuleSearchPath().isPresent()) {
            pythonEnvironmentBuilder.put(PYTHONPATH_ENV_VAR_NAME, options.getPythonModuleSearchPath().get());
        }
        ImmutableMap<String, String> pythonEnvironment = pythonEnvironmentBuilder.build();
        ProcessExecutorParams params = ProcessExecutorParams.builder().setCommand(buildArgs()).setEnvironment(pythonEnvironment).build();
        LOG.debug("Starting buck.py command: %s environment: %s", params.getCommand(), params.getEnvironment());
        buckPyProcess = processExecutor.launchProcess(params);
        LOG.debug("Started process %s successfully", buckPyProcess);
        OutputStream stdin = buckPyProcess.getOutputStream();
        InputStream stderr = buckPyProcess.getErrorStream();
        InputStreamConsumer stderrConsumer = new InputStreamConsumer(stderr, (InputStreamConsumer.Handler) line -> buckEventBus.post(ConsoleEvent.warning("Warning raised by BUCK file parser: %s", line)));
        stderrConsumerTerminationFuture = new FutureTask<>(stderrConsumer);
        stderrConsumerThread = Threads.namedThread(ProjectBuildFileParser.class.getSimpleName(), stderrConsumerTerminationFuture);
        stderrConsumerThread.start();
        buckPyStdinWriter = new BufferedOutputStream(stdin);
    }
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) ProjectWatch(com.facebook.buck.io.ProjectWatch) PerfEventId(com.facebook.buck.event.PerfEventId) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent) Supplier(com.google.common.base.Supplier) FutureTask(java.util.concurrent.FutureTask) WatchmanDiagnosticEvent(com.facebook.buck.io.WatchmanDiagnosticEvent) ConsoleEvent(com.facebook.buck.event.ConsoleEvent) BufferedOutputStream(java.io.BufferedOutputStream) Strings(com.google.common.base.Strings) ImmutableList(com.google.common.collect.ImmutableList) ProcessExecutor(com.facebook.buck.util.ProcessExecutor) Value(org.immutables.value.Value) BserSerializer(com.facebook.buck.bser.BserSerializer) Map(java.util.Map) BserDeserializer(com.facebook.buck.bser.BserDeserializer) Suppliers(com.google.common.base.Suppliers) BuckStyleTuple(com.facebook.buck.util.immutables.BuckStyleTuple) Path(java.nio.file.Path) Nullable(javax.annotation.Nullable) MoreCollectors(com.facebook.buck.util.MoreCollectors) OutputStream(java.io.OutputStream) Logger(com.facebook.buck.log.Logger) WatchmanDiagnostic(com.facebook.buck.io.WatchmanDiagnostic) MoreThrowables(com.facebook.buck.util.MoreThrowables) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Files(java.nio.file.Files) Threads(com.facebook.buck.util.Threads) IOException(java.io.IOException) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) PathOrGlobMatcher(com.facebook.buck.io.PathOrGlobMatcher) Maps(com.google.common.collect.Maps) ExecutionException(java.util.concurrent.ExecutionException) ConstructorArgMarshaller(com.facebook.buck.rules.ConstructorArgMarshaller) List(java.util.List) Paths(java.nio.file.Paths) AssertScopeExclusiveAccess(com.facebook.buck.util.concurrent.AssertScopeExclusiveAccess) Optional(java.util.Optional) Preconditions(com.google.common.base.Preconditions) VisibleForTesting(com.google.common.annotations.VisibleForTesting) InputStreamConsumer(com.facebook.buck.util.InputStreamConsumer) Collections(java.util.Collections) Description(com.facebook.buck.rules.Description) InputStream(java.io.InputStream) ProcessExecutorParams(com.facebook.buck.util.ProcessExecutorParams) InputStreamConsumer(com.facebook.buck.util.InputStreamConsumer) InputStream(java.io.InputStream) BufferedOutputStream(java.io.BufferedOutputStream) OutputStream(java.io.OutputStream) ImmutableMap(com.google.common.collect.ImmutableMap) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent) BufferedOutputStream(java.io.BufferedOutputStream)

Aggregations

BserDeserializer (com.facebook.buck.bser.BserDeserializer)1 BserSerializer (com.facebook.buck.bser.BserSerializer)1 BuckEventBus (com.facebook.buck.event.BuckEventBus)1 ConsoleEvent (com.facebook.buck.event.ConsoleEvent)1 PerfEventId (com.facebook.buck.event.PerfEventId)1 SimplePerfEvent (com.facebook.buck.event.SimplePerfEvent)1 PathOrGlobMatcher (com.facebook.buck.io.PathOrGlobMatcher)1 ProjectWatch (com.facebook.buck.io.ProjectWatch)1 WatchmanDiagnostic (com.facebook.buck.io.WatchmanDiagnostic)1 WatchmanDiagnosticEvent (com.facebook.buck.io.WatchmanDiagnosticEvent)1 Logger (com.facebook.buck.log.Logger)1 ConstructorArgMarshaller (com.facebook.buck.rules.ConstructorArgMarshaller)1 Description (com.facebook.buck.rules.Description)1 InputStreamConsumer (com.facebook.buck.util.InputStreamConsumer)1 MoreCollectors (com.facebook.buck.util.MoreCollectors)1 MoreThrowables (com.facebook.buck.util.MoreThrowables)1 ProcessExecutor (com.facebook.buck.util.ProcessExecutor)1 ProcessExecutorParams (com.facebook.buck.util.ProcessExecutorParams)1 Threads (com.facebook.buck.util.Threads)1 AssertScopeExclusiveAccess (com.facebook.buck.util.concurrent.AssertScopeExclusiveAccess)1