diff options
author | felly <felly@google.com> | 2018-06-11 11:08:44 -0700 |
---|---|---|
committer | Copybara-Service <copybara-piper@google.com> | 2018-06-11 11:09:56 -0700 |
commit | d1faf43493a6d11deb5bd88373ceb5fab04c8109 (patch) | |
tree | 3c1231cc8f8beb54814343a2b244fde4b3d2bc3f /src/main/java/com/google/devtools/build | |
parent | d2e0a947963f7f725d5bac69391ad9797f4a9beb (diff) |
Allow delegation to the underlying filesystem only for the source tree.
The on-disk execRoot/blaze-out is now off limits to ActionFS.
RELNOTES: None
PiperOrigin-RevId: 200080287
Diffstat (limited to 'src/main/java/com/google/devtools/build')
3 files changed, 22 insertions, 12 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 63ddb692d6..46d81b475c 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 @@ -37,6 +37,7 @@ import com.google.devtools.build.lib.actions.FilesetOutputSymlink; import com.google.devtools.build.lib.actions.MissingInputFileException; import com.google.devtools.build.lib.actions.NotifyOnActionCacheHit; import com.google.devtools.build.lib.actions.PackageRootResolver; +import com.google.devtools.build.lib.analysis.BlazeDirectories; import com.google.devtools.build.lib.causes.Cause; import com.google.devtools.build.lib.causes.LabelCause; import com.google.devtools.build.lib.clock.BlazeClock; @@ -82,12 +83,15 @@ import javax.annotation.Nullable; */ public class ActionExecutionFunction implements SkyFunction, CompletionReceiver { private final SkyframeActionExecutor skyframeActionExecutor; + private final BlazeDirectories directories; private final AtomicReference<TimestampGranularityMonitor> tsgm; private ConcurrentMap<Action, ContinuationState> stateMap; public ActionExecutionFunction(SkyframeActionExecutor skyframeActionExecutor, + BlazeDirectories directories, AtomicReference<TimestampGranularityMonitor> tsgm) { this.skyframeActionExecutor = skyframeActionExecutor; + this.directories = directories; this.tsgm = tsgm; stateMap = Maps.newConcurrentMap(); } @@ -213,6 +217,7 @@ public class ActionExecutionFunction implements SkyFunction, CompletionReceiver new ActionFileSystem( skyframeActionExecutor.getExecutorFileSystem(), skyframeActionExecutor.getExecRoot(), + directories.getRelativeOutputPath(), skyframeActionExecutor.getSourceRoots(), checkedInputs.first, optionalInputs, 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 757c310697..726042588b 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 @@ -73,6 +73,7 @@ final class ActionFileSystem extends AbstractFileSystemWithCustomStat private final FileSystem delegate; private final PathFragment execRootFragment; + private final PathFragment outputPathFragment; private final ImmutableList<PathFragment> sourceRoots; private final ActionInputMap inputArtifactData; @@ -97,6 +98,7 @@ final class ActionFileSystem extends AbstractFileSystemWithCustomStat ActionFileSystem( FileSystem delegate, Path execRoot, + String relativeOutputPath, ImmutableList<Root> sourceRoots, ActionInputMap inputArtifactData, Iterable<Artifact> allowedInputs, @@ -106,6 +108,7 @@ final class ActionFileSystem extends AbstractFileSystemWithCustomStat this.delegate = delegate; this.execRootFragment = execRoot.asFragment(); + this.outputPathFragment = execRootFragment.getRelative(relativeOutputPath); this.sourceRoots = sourceRoots .stream() @@ -297,7 +300,7 @@ final class ActionFileSystem extends AbstractFileSystemWithCustomStat if (metadata instanceof SourceFileArtifactValue) { return resolveSourcePath((SourceFileArtifactValue) metadata).getxattr(name); } - return delegate.getPath(path.asFragment()).getxattr(name); + return getSourcePath(path.asFragment()).getxattr(name); } @Override @@ -371,6 +374,8 @@ final class ActionFileSystem extends AbstractFileSystemWithCustomStat linkPath, targetFragment, linkPath + " is not an output.")); } if (sourceRootIndex >= 0) { + Preconditions.checkState(!targetExecPath.startsWith(outputPathFragment), "Target exec path " + + "%s does not start with output path fragment %s", targetExecPath, outputPathFragment); outputHolder.set( new SourceFileArtifactValue( targetExecPath, sourceRootIndex, inputMetadata.getDigest(), inputMetadata.getSize()), @@ -430,7 +435,7 @@ final class ActionFileSystem extends AbstractFileSystemWithCustomStat !(metadata instanceof RemoteFileArtifactValue), "getInputStream called for remote file: %s", path); - return delegate.getPath(path.asFragment()).getInputStream(); + return getSourcePath(path.asFragment()).getInputStream(); } @Override @@ -520,13 +525,14 @@ final class ActionFileSystem extends AbstractFileSystemWithCustomStat } private boolean isOutput(Path path) { - // TODO(felly): This method should instead just refer to potential output paths, which are - // anything under the output tree. - PathFragment fragment = path.asFragment(); - if (!fragment.startsWith(execRootFragment)) { - return false; + return path.asFragment().startsWith(outputPathFragment); + } + + private Path getSourcePath(PathFragment path) throws IOException { + if (path.startsWith(outputPathFragment)) { + throw new IOException("ActionFS cannot delegate to underlying output path for " + path); } - return outputs.getIfPresent(fragment.relativeTo(execRootFragment)) != null; + return delegate.getPath(path); } /** @@ -555,9 +561,8 @@ final class ActionFileSystem extends AbstractFileSystemWithCustomStat } /** NB: resolves to the underlying filesytem instead of this one. */ - private Path resolveSourcePath(SourceFileArtifactValue metadata) { - return delegate - .getPath(sourceRoots.get(metadata.getSourceRootIndex())) + private Path resolveSourcePath(SourceFileArtifactValue metadata) throws IOException { + return getSourcePath(sourceRoots.get(metadata.getSourceRootIndex())) .getRelative(metadata.getExecPath()); } diff --git a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java index 4d413a96fb..633b8b873b 100644 --- a/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java +++ b/src/main/java/com/google/devtools/build/lib/skyframe/SkyframeExecutor.java @@ -518,7 +518,7 @@ public abstract class SkyframeExecutor implements WalkableGraphFactory { SkyFunctions.COVERAGE_REPORT, new CoverageReportFunction(actionKeyContext, removeActionsAfterEvaluation)); ActionExecutionFunction actionExecutionFunction = - new ActionExecutionFunction(skyframeActionExecutor, tsgm); + new ActionExecutionFunction(skyframeActionExecutor, directories, tsgm); map.put(SkyFunctions.ACTION_EXECUTION, actionExecutionFunction); this.actionExecutionFunction = actionExecutionFunction; map.put(SkyFunctions.RECURSIVE_FILESYSTEM_TRAVERSAL, |