|
14 | 14 | package com.google.devtools.build.lib.remote;
|
15 | 15 |
|
16 | 16 | import static com.google.common.base.Preconditions.checkArgument;
|
| 17 | +import static com.google.devtools.build.lib.remote.common.ProgressStatusListener.NO_ACTION; |
17 | 18 |
|
18 | 19 | import build.bazel.remote.execution.v2.Digest;
|
19 | 20 | import build.bazel.remote.execution.v2.RequestMetadata;
|
|
24 | 25 | import com.google.devtools.build.lib.actions.FileArtifactValue;
|
25 | 26 | import com.google.devtools.build.lib.actions.cache.VirtualActionInput;
|
26 | 27 | import com.google.devtools.build.lib.actions.cache.VirtualActionInput.EmptyActionInput;
|
| 28 | +import com.google.devtools.build.lib.events.ExtendedEventHandler.FetchProgress; |
27 | 29 | import com.google.devtools.build.lib.events.Reporter;
|
| 30 | +import com.google.devtools.build.lib.exec.SpawnProgressEvent; |
| 31 | +import com.google.devtools.build.lib.remote.RemoteCache.DownloadProgressReporter; |
28 | 32 | import com.google.devtools.build.lib.remote.common.BulkTransferException;
|
29 | 33 | import com.google.devtools.build.lib.remote.common.RemoteActionExecutionContext;
|
30 | 34 | import com.google.devtools.build.lib.remote.util.DigestUtil;
|
@@ -90,15 +94,56 @@ protected boolean canDownloadFile(Path path, FileArtifactValue metadata) {
|
90 | 94 |
|
91 | 95 | @Override
|
92 | 96 | protected ListenableFuture<Void> doDownloadFile(
|
93 |
| - Path tempPath, PathFragment execPath, FileArtifactValue metadata, Priority priority) |
| 97 | + Reporter reporter, |
| 98 | + Path tempPath, |
| 99 | + PathFragment execPath, |
| 100 | + FileArtifactValue metadata, |
| 101 | + Priority priority) |
94 | 102 | throws IOException {
|
95 | 103 | checkArgument(metadata.isRemote(), "Cannot download file that is not a remote file.");
|
96 | 104 | RequestMetadata requestMetadata =
|
97 | 105 | TracingMetadataUtils.buildMetadata(buildRequestId, commandId, metadata.getActionId(), null);
|
98 | 106 | RemoteActionExecutionContext context = RemoteActionExecutionContext.create(requestMetadata);
|
99 | 107 |
|
100 | 108 | Digest digest = DigestUtil.buildDigest(metadata.getDigest(), metadata.getSize());
|
101 |
| - return remoteCache.downloadFile(context, tempPath, digest); |
| 109 | + |
| 110 | + DownloadProgressReporter downloadProgressReporter; |
| 111 | + if (priority == Priority.LOW) { |
| 112 | + // Only report download progress for toplevel outputs |
| 113 | + downloadProgressReporter = |
| 114 | + new DownloadProgressReporter( |
| 115 | + /* includeFile= */ false, |
| 116 | + progress -> reporter.post(new DownloadProgress(progress)), |
| 117 | + execPath.toString(), |
| 118 | + metadata.getSize()); |
| 119 | + } else { |
| 120 | + downloadProgressReporter = new DownloadProgressReporter(NO_ACTION, "", 0); |
| 121 | + } |
| 122 | + |
| 123 | + return remoteCache.downloadFile(context, tempPath, digest, downloadProgressReporter); |
| 124 | + } |
| 125 | + |
| 126 | + public static class DownloadProgress implements FetchProgress { |
| 127 | + private final SpawnProgressEvent progress; |
| 128 | + |
| 129 | + public DownloadProgress(SpawnProgressEvent progress) { |
| 130 | + this.progress = progress; |
| 131 | + } |
| 132 | + |
| 133 | + @Override |
| 134 | + public String getResourceIdentifier() { |
| 135 | + return progress.progressId(); |
| 136 | + } |
| 137 | + |
| 138 | + @Override |
| 139 | + public String getProgress() { |
| 140 | + return progress.progress(); |
| 141 | + } |
| 142 | + |
| 143 | + @Override |
| 144 | + public boolean isFinished() { |
| 145 | + return progress.finished(); |
| 146 | + } |
102 | 147 | }
|
103 | 148 |
|
104 | 149 | @Override
|
|
0 commit comments