Skip to content

Commit

Permalink
Pass ActionFS paths through to action-level FileOutErr for the Action…
Browse files Browse the repository at this point in the history
…'s stdout/stderr.

RELNOTES: None
PiperOrigin-RevId: 200459354
  • Loading branch information
ericfelly authored and Copybara-Service committed Jun 13, 2018
1 parent adb3587 commit fc83d75
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ private ActionExecutionContext(
this.artifactExpander = artifactExpander;
this.env = env;
this.actionFileSystem = actionFileSystem;
this.pathResolver = createPathResolver(actionFileSystem,
this.pathResolver = ArtifactPathResolver.createPathResolver(actionFileSystem,
// executor is only ever null in testing.
executor == null ? null : executor.getExecRoot());
}
Expand Down Expand Up @@ -180,16 +180,6 @@ public Root getRoot(Artifact artifact) {
return pathResolver.transformRoot(artifact.getRoot().getRoot());
}

private static ArtifactPathResolver createPathResolver(FileSystem actionFileSystem,
Path execRoot) {
if (actionFileSystem == null) {
return ArtifactPathResolver.forExecRoot(execRoot);
} else {
return ArtifactPathResolver.withTransformedFileSystem(
actionFileSystem.getPath(execRoot.asFragment()));
}
}

public ArtifactPathResolver getPathResolver() {
return pathResolver;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

import com.google.devtools.build.lib.util.io.FileOutErr;
import com.google.devtools.build.lib.vfs.Path;

import java.util.concurrent.atomic.AtomicInteger;

/**
Expand All @@ -34,9 +33,10 @@ public ActionLogBufferPathGenerator(Path actionOutputRoot) {
/**
* Generates a unique filename for an action to store its output.
*/
public FileOutErr generate() {
public FileOutErr generate(ArtifactPathResolver resolver) {
int actionId = actionCounter.incrementAndGet();
return new FileOutErr(actionOutputRoot.getRelative("stdout-" + actionId),
actionOutputRoot.getRelative("stderr-" + actionId));
return new FileOutErr(
resolver.convertPath(actionOutputRoot.getRelative("stdout-" + actionId)),
resolver.convertPath(actionOutputRoot.getRelative("stderr-" + actionId)));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,29 @@
import com.google.devtools.build.lib.vfs.FileSystem;
import com.google.devtools.build.lib.vfs.Path;
import com.google.devtools.build.lib.vfs.Root;
import javax.annotation.Nullable;

/**
* An indirection layer on Path resolution of {@link Artifact} and {@link Root}.
*
* Serves as converter interface primarily for switching the {@link FileSystem} underyling the
* values.
*/
public interface ArtifactPathResolver {

/**
* @return a resolved Path corresponding to the given actionInput.
*/
Path toPath(ActionInput actionInput);

/**
* @return a resolved Path corresponding to the given path.
*/
Path convertPath(Path path);

/**
* @return a resolved Rooth corresponding to the given Root.
*/
Root transformRoot(Root root);

ArtifactPathResolver IDENTITY = new IdentityResolver(null);
Expand All @@ -35,6 +52,16 @@ static ArtifactPathResolver withTransformedFileSystem(Path execRoot) {
return new TransformResolver(execRoot);
}

static ArtifactPathResolver createPathResolver(@Nullable FileSystem fileSystem,
Path execRoot) {
if (fileSystem == null) {
return forExecRoot(execRoot);
} else {
return withTransformedFileSystem(
fileSystem.getPath(execRoot.asFragment()));
}
}

/**
* Path resolution that uses an Artifact's path directly, or looks up the input execPath relative
* to the given execRoot.
Expand All @@ -58,6 +85,11 @@ public Path toPath(ActionInput actionInput) {
public Root transformRoot(Root root) {
return Preconditions.checkNotNull(root);
}

@Override
public Path convertPath(Path path) {
return path;
}
};

/**
Expand All @@ -84,5 +116,10 @@ public Path toPath(ActionInput input) {
public Root transformRoot(Root root) {
return Root.toFileSystem(Preconditions.checkNotNull(root), fileSystem);
}

@Override
public Path convertPath(Path path) {
return fileSystem.getPath(path.asFragment());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
import com.google.devtools.build.lib.actions.Artifact;
import com.google.devtools.build.lib.actions.Artifact.ArtifactExpander;
import com.google.devtools.build.lib.actions.Artifact.OwnerlessArtifactWrapper;
import com.google.devtools.build.lib.actions.ArtifactPathResolver;
import com.google.devtools.build.lib.actions.ArtifactPrefixConflictException;
import com.google.devtools.build.lib.actions.CachedActionEvent;
import com.google.devtools.build.lib.actions.EnvironmentalExecException;
Expand Down Expand Up @@ -520,7 +521,8 @@ public ActionExecutionContext getContext(
Map<Artifact, Collection<Artifact>> expandedInputs,
ImmutableMap<PathFragment, ImmutableList<FilesetOutputSymlink>> inputFilesetMappings,
@Nullable ActionFileSystem actionFileSystem) {
FileOutErr fileOutErr = actionLogBufferPathGenerator.generate();
FileOutErr fileOutErr = actionLogBufferPathGenerator.generate(
ArtifactPathResolver.createPathResolver(actionFileSystem, executorEngine.getExecRoot()));
return new ActionExecutionContext(
executorEngine,
createFileCache(graphFileCache, actionFileSystem),
Expand Down Expand Up @@ -655,7 +657,8 @@ Iterable<Artifact> discoverInputs(
actionInputPrefetcher,
actionKeyContext,
metadataHandler,
actionLogBufferPathGenerator.generate(),
actionLogBufferPathGenerator.generate(ArtifactPathResolver.createPathResolver(
actionFileSystem, executorEngine.getExecRoot())),
clientEnv,
env,
actionFileSystem);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import com.google.devtools.build.lib.actions.Artifact.ArtifactExpander;
import com.google.devtools.build.lib.actions.Artifact.SpecialArtifact;
import com.google.devtools.build.lib.actions.ArtifactOwner;
import com.google.devtools.build.lib.actions.ArtifactPathResolver;
import com.google.devtools.build.lib.actions.ArtifactRoot;
import com.google.devtools.build.lib.actions.CommandAction;
import com.google.devtools.build.lib.actions.CommandLine;
Expand Down Expand Up @@ -2121,7 +2122,7 @@ public ActionExecutionContext build() {
/*actionInputPrefetcher=*/ null,
actionKeyContext,
/*metadataHandler=*/ null,
actionLogBufferPathGenerator.generate(),
actionLogBufferPathGenerator.generate(ArtifactPathResolver.IDENTITY),
clientEnv,
ImmutableMap.of(),
artifactExpander,
Expand Down

0 comments on commit fc83d75

Please sign in to comment.