Skip to content

Commit

Permalink
Take no action to prefetch empty artifacts.
Browse files Browse the repository at this point in the history
Previously, Bazel would attempt to overwrite /dev/null.

Closes bazelbuild#12514.

PiperOrigin-RevId: 343824719
  • Loading branch information
benjaminp authored and copybara-github committed Nov 23, 2020
1 parent 2217b52 commit a87d7ed
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import com.google.devtools.build.lib.actions.FileArtifactValue;
import com.google.devtools.build.lib.actions.MetadataProvider;
import com.google.devtools.build.lib.actions.cache.VirtualActionInput;
import com.google.devtools.build.lib.actions.cache.VirtualActionInput.EmptyActionInput;
import com.google.devtools.build.lib.profiler.Profiler;
import com.google.devtools.build.lib.profiler.ProfilerTask;
import com.google.devtools.build.lib.profiler.SilentCloseable;
Expand Down Expand Up @@ -94,9 +95,11 @@ public void prefetchFiles(
Map<Path, ListenableFuture<Void>> downloadsToWaitFor = new HashMap<>();
for (ActionInput input : inputs) {
if (input instanceof VirtualActionInput) {
VirtualActionInput virtualActionInput = (VirtualActionInput) input;
Path outputPath = execRoot.getRelative(virtualActionInput.getExecPath());
SandboxHelpers.atomicallyWriteVirtualInput(virtualActionInput, outputPath, ".remote");
if (!(input instanceof EmptyActionInput)) {
VirtualActionInput virtualActionInput = (VirtualActionInput) input;
Path outputPath = execRoot.getRelative(virtualActionInput.getExecPath());
SandboxHelpers.atomicallyWriteVirtualInput(virtualActionInput, outputPath, ".remote");
}
} else {
FileArtifactValue metadata = metadataProvider.getMetadata(input);
if (metadata == null || !metadata.isRemote()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import com.google.devtools.build.lib.actions.cache.VirtualActionInput;
import com.google.devtools.build.lib.actions.util.ActionsTestUtil;
import com.google.devtools.build.lib.clock.JavaClock;
import com.google.devtools.build.lib.exec.SpawnInputExpander;
import com.google.devtools.build.lib.remote.options.RemoteOptions;
import com.google.devtools.build.lib.remote.util.DigestUtil;
import com.google.devtools.build.lib.remote.util.InMemoryCacheClient;
Expand Down Expand Up @@ -74,6 +75,9 @@ public void setUp() throws IOException {
FileSystem fs = new InMemoryFileSystem(new JavaClock(), HASH_FUNCTION);
execRoot = fs.getPath("/exec");
execRoot.createDirectoryAndParents();
Path dev = fs.getPath("/dev");
dev.createDirectory();
dev.setWritable(false);
artifactRoot = ArtifactRoot.asDerivedRoot(execRoot, "root");
artifactRoot.getRoot().asPath().createDirectoryAndParents();
options = Options.getDefaults(RemoteOptions.class);
Expand Down Expand Up @@ -127,6 +131,23 @@ public void testStagingVirtualActionInput() throws Exception {
assertThat(actionInputFetcher.downloadsInProgress).isEmpty();
}

@Test
public void testStagingEmptyVirtualActionInput() throws Exception {
// arrange
MetadataProvider metadataProvider = new StaticMetadataProvider(new HashMap<>());
RemoteCache remoteCache = newCache(options, digestUtil, new HashMap<>());
RemoteActionInputFetcher actionInputFetcher =
new RemoteActionInputFetcher(remoteCache, execRoot, RequestMetadata.getDefaultInstance());

// act
actionInputFetcher.prefetchFiles(
ImmutableList.of(SpawnInputExpander.EMPTY_FILE), metadataProvider);

// assert that nothing happened
assertThat(actionInputFetcher.downloadedFiles()).isEmpty();
assertThat(actionInputFetcher.downloadsInProgress).isEmpty();
}

@Test
public void testFileNotFound() throws Exception {
// Test that we get an exception if an input file is missing
Expand Down

0 comments on commit a87d7ed

Please sign in to comment.