remote: Add a SingleSourceBuilder to the Chunker.
Prepare the Chunker for an upcoming refactoring, where it will no longer
support multiple input sources and digest filtering.
RELNOTES: None.
package com.google.devtools.build.lib.remote;
+import static com.google.devtools.build.lib.util.Preconditions.checkArgument;
+import static com.google.devtools.build.lib.util.Preconditions.checkState;
+
import com.google.common.annotations.VisibleForTesting;
import com.google.common.base.Predicate;
import com.google.common.collect.ImmutableList;
@@ -254,10 +257,54 @@ public final class Chunker {
}
}
+ /**
+ * Creates a Chunker from a single input source.
+ *
+ * <p>As we phase out usages of multiple input sources, this will soon completely replace the
+ * multiple inputs Builder.
+ */
+ public static final class SingleSourceBuilder {
+ private Item item;
+ private int chunkSize = getDefaultChunkSize();
+
+ public SingleSourceBuilder chunkSize(int chunkSize) {
+ checkArgument(chunkSize > 0, "chunkSize must be gt 0.");
+ this.chunkSize = chunkSize;
+ return this;
+ }
+
+ public SingleSourceBuilder input(byte[] blob) {
+ item = toItem(blob);
+ return this;
+ }
+
+ public SingleSourceBuilder input(Path file) {
+ item = toItem(file);
+ return this;
+ }
+
+ public SingleSourceBuilder input(ActionInput input, ActionInputFileCache inputCache,
+ Path execRoot) {
+ item = toItem(input, inputCache, execRoot);
+ return this;
+ }
+
+ public Digest getDigest() throws IOException {
+ checkState(item != null, "Need to specify an input source first.");
+ return item.getDigest();
+ }
+
+ public Chunker build() throws IOException {
+ checkState(item != null, "No input source provided.");
+ return new Chunker(item, chunkSize);
+ }
+ }
+
/**
* Create a Chunker from multiple input sources. The order of the sources provided to the Builder
* will be the same order they will be chunked by.
*/
+ @Deprecated
public static final class Builder {
private final ImmutableList.Builder<Item> items = ImmutableList.builder();
private Set<Digest> digests = null;
