Search in sources :

Example 1 with ThreadSafe

use of javax.annotation.concurrent.ThreadSafe in project buck by facebook.

the class TargetNodeParsePipeline method computeNode.

@Override
protected TargetNode<?, ?> computeNode(final Cell cell, final BuildTarget buildTarget, final Map<String, Object> rawNode) throws BuildTargetException {
    try (final SimplePerfEvent.Scope scope = SimplePerfEvent.scopeIgnoringShortEvents(eventBus, PerfEventId.of("GetTargetNode"), "target", buildTarget, targetNodePipelineLifetimeEventScope, getMinimumPerfEventTimeMs(), TimeUnit.MILLISECONDS)) {
        Function<PerfEventId, SimplePerfEvent.Scope> perfEventScopeFunction = perfEventId -> SimplePerfEvent.scopeIgnoringShortEvents(eventBus, perfEventId, scope, getMinimumPerfEventTimeMs(), TimeUnit.MILLISECONDS);
        final TargetNode<?, ?> targetNode = delegate.createTargetNode(cell, cell.getAbsolutePathToBuildFile(buildTarget), buildTarget, rawNode, perfEventScopeFunction);
        if (speculativeDepsTraversal) {
            executorService.submit(() -> {
                for (BuildTarget depTarget : targetNode.getDeps()) {
                    Path depCellPath = depTarget.getCellPath();
                    // non-threadsafe way making it inconvenient to access from the pipeline.
                    if (depCellPath.equals(cell.getRoot())) {
                        try {
                            if (depTarget.isFlavored()) {
                                getNodeJob(cell, BuildTarget.of(depTarget.getUnflavoredBuildTarget()));
                            }
                            getNodeJob(cell, depTarget);
                        } catch (BuildTargetException e) {
                            // No biggie, we'll hit the error again in the non-speculative path.
                            LOG.info(e, "Could not schedule speculative parsing for %s", depTarget);
                        }
                    }
                }
            });
        }
        return targetNode;
    }
}
Also used : BuckEventBus(com.facebook.buck.event.BuckEventBus) Logger(com.facebook.buck.log.Logger) PerfEventId(com.facebook.buck.event.PerfEventId) Function(com.google.common.base.Function) ImmutableSet(com.google.common.collect.ImmutableSet) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TargetNode(com.facebook.buck.rules.TargetNode) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent) BuildTargetException(com.facebook.buck.model.BuildTargetException) ThreadSafe(javax.annotation.concurrent.ThreadSafe) BuildTarget(com.facebook.buck.model.BuildTarget) TimeUnit(java.util.concurrent.TimeUnit) Map(java.util.Map) Cache(com.facebook.buck.parser.PipelineNodeCache.Cache) Cell(com.facebook.buck.rules.Cell) Path(java.nio.file.Path) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) Path(java.nio.file.Path) BuildTargetException(com.facebook.buck.model.BuildTargetException) PerfEventId(com.facebook.buck.event.PerfEventId) BuildTarget(com.facebook.buck.model.BuildTarget) SimplePerfEvent(com.facebook.buck.event.SimplePerfEvent)

Aggregations

BuckEventBus (com.facebook.buck.event.BuckEventBus)1 PerfEventId (com.facebook.buck.event.PerfEventId)1 SimplePerfEvent (com.facebook.buck.event.SimplePerfEvent)1 Logger (com.facebook.buck.log.Logger)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 BuildTargetException (com.facebook.buck.model.BuildTargetException)1 Cache (com.facebook.buck.parser.PipelineNodeCache.Cache)1 Cell (com.facebook.buck.rules.Cell)1 TargetNode (com.facebook.buck.rules.TargetNode)1 Function (com.google.common.base.Function)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)1 Path (java.nio.file.Path)1 Map (java.util.Map)1 TimeUnit (java.util.concurrent.TimeUnit)1 ThreadSafe (javax.annotation.concurrent.ThreadSafe)1