diff options
author | 2018-05-30 10:46:40 -0700 | |
---|---|---|
committer | 2018-05-30 10:48:22 -0700 | |
commit | 252e3b817e444ddfe264e8cbc5f1203023e61926 (patch) | |
tree | 2169737c081cc3cc5e258da1be891f8268dc975e /src/main/java/com/google/devtools/build/lib/skyframe/ActionFileSystem.java | |
parent | 088d8de6584864adaec82712c8ace601404afd0b (diff) |
Adds support for InlineFileArtifactValue.
PiperOrigin-RevId: 198584000
Diffstat (limited to 'src/main/java/com/google/devtools/build/lib/skyframe/ActionFileSystem.java')
-rw-r--r-- | src/main/java/com/google/devtools/build/lib/skyframe/ActionFileSystem.java | 36 |
1 files changed, 29 insertions, 7 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionFileSystem.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionFileSystem.java index 5b35c40f0e..d6d695cd71 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionFileSystem.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionFileSystem.java @@ -19,6 +19,7 @@ import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableMap; import com.google.common.collect.Streams; +import com.google.common.hash.Hashing; import com.google.common.io.BaseEncoding; import com.google.devtools.build.lib.actions.ActionInput; import com.google.devtools.build.lib.actions.ActionInputFileCache; @@ -32,6 +33,7 @@ import com.google.devtools.build.lib.vfs.PathFragment; import com.google.devtools.build.lib.vfs.Root; import com.google.devtools.build.skyframe.SkyFunction; import com.google.protobuf.ByteString; +import java.io.ByteArrayOutputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; @@ -338,18 +340,23 @@ final class ActionFileSystem extends FileSystem implements ActionInputFileCache @Override protected InputStream getInputStream(Path path) throws IOException { - // TODO(shahan): cleanup callers of this method and disable or maybe figure out a reasonable - // implementation. - LOGGER.severe("Raw read of path: " + path); + FileArtifactValue metadata = getMetadataChecked(asExecPath(path)); + if (metadata instanceof FileArtifactValue.InlineFileArtifactValue) { + return ((FileArtifactValue.InlineFileArtifactValue) metadata).getInputStream(); + } + Preconditions.checkArgument( + !(metadata instanceof FileArtifactValue.RemoteFileArtifactValue), + "getInputStream called for remote file: %s", + path); return delegate.getPath(path.asFragment()).getInputStream(); } @Override protected OutputStream getOutputStream(Path path, boolean append) throws IOException { - // TODO(shahan): cleanup callers of this method and disable or maybe figure out a reasonable - // implementation. - LOGGER.severe("Raw write of path: " + path); - return delegate.getPath(path.asFragment()).getOutputStream(append); + Preconditions.checkArgument(!append, "ActionFileSystem doesn't support append."); + return Preconditions.checkNotNull( + outputs.get(asExecPath(path)), "getOutputStream called for non-output: %s", path) + .getOutputStream(); } @Override @@ -520,5 +527,20 @@ final class ActionFileSystem extends FileSystem implements ActionInputFileCache metadataConsumer.accept(artifact, metadata); this.metadata = metadata; } + + /** Callers are expected to close the returned stream. */ + public ByteArrayOutputStream getOutputStream() { + Preconditions.checkState(metadata == null, "getOutputStream called twice for: %s", artifact); + return new ByteArrayOutputStream() { + @Override + public void close() throws IOException { + super.close(); + byte[] data = toByteArray(); + set( + new FileArtifactValue.InlineFileArtifactValue( + data, Hashing.md5().hashBytes(data).asBytes())); + } + }; + } } } |