aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java2
-rw-r--r--src/main/java/com/google/devtools/build/lib/skyframe/ActionFileSystem.java13
-rw-r--r--src/test/java/com/google/devtools/build/lib/skyframe/ActionFileSystemTest.java85
3 files changed, 95 insertions, 5 deletions
diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java b/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java
index 46d81b475c..612632e0f6 100644
--- a/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java
+++ b/src/main/java/com/google/devtools/build/lib/skyframe/ActionExecutionFunction.java
@@ -216,7 +216,7 @@ public class ActionExecutionFunction implements SkyFunction, CompletionReceiver
state.actionFileSystem =
new ActionFileSystem(
skyframeActionExecutor.getExecutorFileSystem(),
- skyframeActionExecutor.getExecRoot(),
+ skyframeActionExecutor.getExecRoot().asFragment(),
directories.getRelativeOutputPath(),
skyframeActionExecutor.getSourceRoots(),
checkedInputs.first,
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 af2fe79920..bb4904283c 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
@@ -97,7 +97,7 @@ final class ActionFileSystem extends AbstractFileSystemWithCustomStat
ActionFileSystem(
FileSystem delegate,
- Path execRoot,
+ PathFragment execRoot,
String relativeOutputPath,
ImmutableList<Root> sourceRoots,
ActionInputMap inputArtifactData,
@@ -107,7 +107,7 @@ final class ActionFileSystem extends AbstractFileSystemWithCustomStat
Profiler.instance().profile(ProfilerTask.ACTION_FS_STAGING, "staging")) {
this.delegate = delegate;
- this.execRootFragment = execRoot.asFragment();
+ this.execRootFragment = execRoot;
this.outputPathFragment = execRootFragment.getRelative(relativeOutputPath);
this.sourceRoots =
sourceRoots
@@ -639,10 +639,15 @@ final class ActionFileSystem extends AbstractFileSystemWithCustomStat
return new ByteArrayOutputStream() {
@Override
public void close() throws IOException {
+ flush();
super.close();
+ }
+
+ @Override
+ public void flush() throws IOException {
+ super.flush();
byte[] data = toByteArray();
- set(
- new InlineFileArtifactValue(data, Hashing.md5().hashBytes(data).asBytes()),
+ set(new InlineFileArtifactValue(data, Hashing.md5().hashBytes(data).asBytes()),
/*notifyConsumer=*/ true);
}
};
diff --git a/src/test/java/com/google/devtools/build/lib/skyframe/ActionFileSystemTest.java b/src/test/java/com/google/devtools/build/lib/skyframe/ActionFileSystemTest.java
new file mode 100644
index 0000000000..d7b5e78127
--- /dev/null
+++ b/src/test/java/com/google/devtools/build/lib/skyframe/ActionFileSystemTest.java
@@ -0,0 +1,85 @@
+// Copyright 2018 The Bazel Authors. All rights reserved.
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+package com.google.devtools.build.lib.skyframe;
+
+import static com.google.common.truth.Truth.assertThat;
+
+import com.google.common.collect.ImmutableList;
+import com.google.devtools.build.lib.actions.ActionInputMap;
+import com.google.devtools.build.lib.vfs.FileSystem;
+import com.google.devtools.build.lib.vfs.FileSystemUtils;
+import com.google.devtools.build.lib.vfs.Path;
+import com.google.devtools.build.lib.vfs.PathFragment;
+import com.google.devtools.build.lib.vfs.inmemoryfs.InMemoryFileSystem;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.JUnit4;
+
+/**
+ * Tests for {@link ActionFileSystem}.
+ *
+ * It would be nice to derive from
+ * {@link com.google.devtools.build.lib.vfs.FileSystemTest;FileSystemTest} if/when ActionFileSystem
+ * becomes sufficiently general.
+ */
+@RunWith(JUnit4.class)
+public class ActionFileSystemTest {
+ private ActionFileSystem actionFS;
+ private Path outputPath;
+
+ @Before
+ public void freshFS() {
+ FileSystem delegateFS = new InMemoryFileSystem();
+ PathFragment execRootFragment = PathFragment.create("/path/to/execroot");
+ String relativeOutputPath = "goog-out";
+ actionFS = new ActionFileSystem(delegateFS, execRootFragment, relativeOutputPath,
+ ImmutableList.of(), new ActionInputMap(0), ImmutableList.of(), ImmutableList.of());
+ outputPath = actionFS.getPath(execRootFragment.getRelative(relativeOutputPath));
+ }
+
+ @Test
+ public void testFileWrite() throws Exception {
+ String testData = "abc19";
+
+ Path file = outputPath.getRelative("foo/bar");
+ FileSystemUtils.writeContentAsLatin1(file, testData);
+ assertThat(file.getFileSize()).isEqualTo(testData.length());
+ assertThat(file.exists()).isTrue();
+ assertThat(file.stat().isFile()).isTrue();
+ assertThat(file.stat().isDirectory()).isFalse();
+ }
+
+ @Test
+ public void testFlushedButNotClosedFileWrite() throws Exception {
+ String testData = "abc19";
+
+ Path file = outputPath.getRelative("foo/bar");
+ try (OutputStream out = file.getOutputStream()) {
+ assertThat(file.exists()).isFalse();
+
+ out.write(testData.getBytes(StandardCharsets.ISO_8859_1));
+ assertThat(file.exists()).isFalse();
+
+ out.flush();
+ assertThat(file.getFileSize()).isEqualTo(testData.length());
+ assertThat(file.exists()).isTrue();
+ assertThat(file.stat().isFile()).isTrue();
+ assertThat(file.stat().isDirectory()).isFalse();
+ }
+ assertThat(file.getFileSize()).isEqualTo(testData.length());
+ }
+}