Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Take no action to prefetch empty artifacts. #12514

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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