Search in sources :

Example 1 with Dependency

use of com.google.devtools.build.lib.view.proto.Deps.Dependency in project intellij by bazelbuild.

the class JdepsFileReader method doLoadJdepsFiles.

@Nullable
private JdepsState doLoadJdepsFiles(Project project, BlazeContext context, ArtifactLocationDecoder decoder, @Nullable JdepsState oldState, Collection<TargetIdeInfo> targetsToLoad, SyncMode syncMode) throws InterruptedException, ExecutionException {
    Map<OutputArtifact, TargetKey> fileToTargetMap = Maps.newHashMap();
    for (TargetIdeInfo target : targetsToLoad) {
        BlazeArtifact output = resolveJdepsOutput(decoder, target);
        if (output instanceof OutputArtifact) {
            fileToTargetMap.put((OutputArtifact) output, target.getKey());
        }
    }
    ArtifactsDiff diff = ArtifactsDiff.diffArtifacts(oldState != null ? oldState.getArtifactState() : null, fileToTargetMap.keySet());
    // TODO: handle prefetching for arbitrary OutputArtifacts
    List<OutputArtifact> outputArtifacts = diff.getUpdatedOutputs();
    // already. Additional logging to identify what is going wrong.
    if (!outputArtifacts.isEmpty() && !SyncMode.involvesBlazeBuild(syncMode)) {
        logger.warn("ArtifactDiff: " + outputArtifacts.size() + " outputs need to be updated during SyncMode.NO_BUILD ");
        if (oldState == null) {
            logger.warn("ArtifactDiff: oldState == null, we failed to load prior JdepsState.");
        } else {
            // Do not list all artifacts since it may be pretty long.
            if (oldState.getArtifactState().size() != fileToTargetMap.size()) {
                logger.warn("Existing artifact state does not match with target map." + " [oldState.getArtifactState().size() = " + oldState.getArtifactState().size() + ", fileToTargetMap.size() = " + fileToTargetMap.size() + "]");
            }
        }
    }
    ListenableFuture<?> downloadArtifactsFuture = RemoteArtifactPrefetcher.getInstance().downloadArtifacts(/* projectName= */
    project.getName(), /* outputArtifacts= */
    BlazeArtifact.getRemoteArtifacts(outputArtifacts));
    ListenableFuture<?> fetchLocalFilesFuture = PrefetchService.getInstance().prefetchFiles(BlazeArtifact.getLocalFiles(outputArtifacts), true, false);
    if (!FutureUtil.waitForFuture(context, Futures.allAsList(downloadArtifactsFuture, fetchLocalFilesFuture)).timed("FetchJdeps", EventType.Prefetching).withProgressMessage("Reading jdeps files...").run().success()) {
        return null;
    }
    AtomicLong totalSizeLoaded = new AtomicLong(0);
    List<ListenableFuture<Result>> futures = Lists.newArrayList();
    for (OutputArtifact updatedFile : outputArtifacts) {
        futures.add(FetchExecutor.EXECUTOR.submit(() -> {
            totalSizeLoaded.addAndGet(updatedFile.getLength());
            try (InputStream inputStream = updatedFile.getInputStream()) {
                Deps.Dependencies dependencies = Deps.Dependencies.parseFrom(inputStream);
                if (dependencies == null) {
                    return null;
                }
                List<String> deps = dependencies.getDependencyList().stream().filter(dep -> relevantDep(dep)).map(Dependency::getPath).collect(toImmutableList());
                TargetKey targetKey = fileToTargetMap.get(updatedFile);
                return new Result(updatedFile, targetKey, deps);
            } catch (IOException e) {
                logger.info("Could not read jdeps file: " + updatedFile);
                return null;
            }
        }));
    }
    JdepsState.Builder state = JdepsState.builder();
    if (oldState != null) {
        state.list.addAll(oldState.data);
    }
    state.removeArtifacts(diff.getUpdatedOutputs().stream().map(OutputArtifact::toArtifactState).collect(toImmutableList()));
    state.removeArtifacts(diff.getRemovedOutputs());
    for (Result result : Futures.allAsList(futures).get()) {
        if (result != null) {
            state.list.add(JdepsData.create(result.targetKey, result.dependencies, result.output.toArtifactState()));
        }
    }
    context.output(PrintOutput.log(String.format("Loaded %d jdeps files, total size %dkB", diff.getUpdatedOutputs().size(), totalSizeLoaded.get() / 1024)));
    return state.build();
}
Also used : BlazeContext(com.google.idea.blaze.base.scope.BlazeContext) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) PrefetchService(com.google.idea.blaze.base.prefetch.PrefetchService) Dependency(com.google.devtools.build.lib.view.proto.Deps.Dependency) JavaIdeInfo(com.google.idea.blaze.base.ideinfo.JavaIdeInfo) ArtifactsDiff(com.google.idea.blaze.base.filecache.ArtifactsDiff) ProcessCanceledException(com.intellij.openapi.progress.ProcessCanceledException) Lists(com.google.common.collect.Lists) Scope(com.google.idea.blaze.base.scope.Scope) JdepsData(com.google.idea.blaze.java.sync.jdeps.JdepsState.JdepsData) Map(java.util.Map) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) Project(com.intellij.openapi.project.Project) Logger(com.intellij.openapi.diagnostic.Logger) Nullable(javax.annotation.Nullable) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) Collection(java.util.Collection) FutureUtil(com.google.idea.blaze.base.async.FutureUtil) SyncState(com.google.idea.blaze.base.model.SyncState) IOException(java.io.IOException) RemoteArtifactPrefetcher(com.google.idea.blaze.base.prefetch.RemoteArtifactPrefetcher) PrintOutput(com.google.idea.blaze.base.scope.output.PrintOutput) Maps(com.google.common.collect.Maps) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) OutputArtifact(com.google.idea.blaze.base.command.buildresult.OutputArtifact) ExecutionException(java.util.concurrent.ExecutionException) AtomicLong(java.util.concurrent.atomic.AtomicLong) Futures(com.google.common.util.concurrent.Futures) List(java.util.List) Deps(com.google.devtools.build.lib.view.proto.Deps) TimingScope(com.google.idea.blaze.base.scope.scopes.TimingScope) SyncMode(com.google.idea.blaze.base.sync.SyncMode) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) FetchExecutor(com.google.idea.blaze.base.prefetch.FetchExecutor) ArtifactLocationDecoder(com.google.idea.blaze.base.sync.workspace.ArtifactLocationDecoder) EventType(com.google.idea.blaze.base.scope.scopes.TimingScope.EventType) InputStream(java.io.InputStream) ArtifactsDiff(com.google.idea.blaze.base.filecache.ArtifactsDiff) InputStream(java.io.InputStream) BlazeArtifact(com.google.idea.blaze.base.command.buildresult.BlazeArtifact) Dependency(com.google.devtools.build.lib.view.proto.Deps.Dependency) IOException(java.io.IOException) TargetIdeInfo(com.google.idea.blaze.base.ideinfo.TargetIdeInfo) AtomicLong(java.util.concurrent.atomic.AtomicLong) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ImmutableList.toImmutableList(com.google.common.collect.ImmutableList.toImmutableList) List(java.util.List) TargetKey(com.google.idea.blaze.base.ideinfo.TargetKey) OutputArtifact(com.google.idea.blaze.base.command.buildresult.OutputArtifact) Nullable(javax.annotation.Nullable)

Aggregations

ImmutableList.toImmutableList (com.google.common.collect.ImmutableList.toImmutableList)1 Lists (com.google.common.collect.Lists)1 Maps (com.google.common.collect.Maps)1 Futures (com.google.common.util.concurrent.Futures)1 ListenableFuture (com.google.common.util.concurrent.ListenableFuture)1 Deps (com.google.devtools.build.lib.view.proto.Deps)1 Dependency (com.google.devtools.build.lib.view.proto.Deps.Dependency)1 FutureUtil (com.google.idea.blaze.base.async.FutureUtil)1 BlazeArtifact (com.google.idea.blaze.base.command.buildresult.BlazeArtifact)1 OutputArtifact (com.google.idea.blaze.base.command.buildresult.OutputArtifact)1 ArtifactsDiff (com.google.idea.blaze.base.filecache.ArtifactsDiff)1 JavaIdeInfo (com.google.idea.blaze.base.ideinfo.JavaIdeInfo)1 TargetIdeInfo (com.google.idea.blaze.base.ideinfo.TargetIdeInfo)1 TargetKey (com.google.idea.blaze.base.ideinfo.TargetKey)1 SyncState (com.google.idea.blaze.base.model.SyncState)1 FetchExecutor (com.google.idea.blaze.base.prefetch.FetchExecutor)1 PrefetchService (com.google.idea.blaze.base.prefetch.PrefetchService)1 RemoteArtifactPrefetcher (com.google.idea.blaze.base.prefetch.RemoteArtifactPrefetcher)1 BlazeContext (com.google.idea.blaze.base.scope.BlazeContext)1 Scope (com.google.idea.blaze.base.scope.Scope)1