blob: 4420ad624699ea97a955a701e05ea25e0fa1cc57 [file] [log] [blame]
Damien Martin-Guillerezf88f4d82015-09-25 13:56:55 +00001// Copyright 2014 The Bazel Authors. All rights reserved.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +01002//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
shahane35e8cf2018-06-18 08:14:01 -070015package com.google.devtools.build.lib.vfs;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010016
shahane35e8cf2018-06-18 08:14:01 -070017import com.google.common.collect.ImmutableList;
felly943a9c72018-08-09 12:55:47 -070018import com.google.common.collect.ImmutableMap;
Eric Fellheimerf3b43af2015-11-13 19:51:20 +000019import com.google.devtools.build.lib.actions.Action;
shahane35e8cf2018-06-18 08:14:01 -070020import com.google.devtools.build.lib.actions.ActionInputMap;
21import com.google.devtools.build.lib.actions.Artifact;
shahan5b0e0712018-10-17 07:41:03 -070022import com.google.devtools.build.lib.actions.Artifact.SourceArtifact;
tomlu880508c2018-08-03 11:21:29 -070023import com.google.devtools.build.lib.actions.ArtifactPathResolver;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010024import com.google.devtools.build.lib.actions.BuildFailedException;
Eric Fellheimerf3b43af2015-11-13 19:51:20 +000025import com.google.devtools.build.lib.actions.EnvironmentalExecException;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010026import com.google.devtools.build.lib.actions.ExecException;
felly943a9c72018-08-09 12:55:47 -070027import com.google.devtools.build.lib.actions.FilesetOutputSymlink;
shahane35e8cf2018-06-18 08:14:01 -070028import com.google.devtools.build.lib.actions.MetadataConsumer;
Eric Fellheimerf3b43af2015-11-13 19:51:20 +000029import com.google.devtools.build.lib.actions.cache.MetadataHandler;
ulfjack75483b52017-07-11 13:36:41 +020030import com.google.devtools.build.lib.events.EventHandler;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010031import com.google.devtools.build.lib.util.AbruptExitException;
felly943a9c72018-08-09 12:55:47 -070032import com.google.devtools.build.skyframe.SkyFunction.Environment;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010033import java.io.IOException;
tomlufe1dd882018-08-15 12:17:42 -070034import java.util.Collection;
35import java.util.Map;
Eric Fellheimer2db6a742015-04-28 21:38:43 +000036import java.util.UUID;
shahan5b0e0712018-10-17 07:41:03 -070037import java.util.function.Function;
shahane35e8cf2018-06-18 08:14:01 -070038import javax.annotation.Nullable;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010039
40/**
41 * An OutputService retains control over the Blaze output tree, and provides a higher level of
42 * abstraction compared to the VFS layer.
43 *
44 * <p>Higher-level facilities include batch statting, cleaning the output tree, creating symlink
45 * trees, and out-of-band insertion of metadata into the tree.
46 */
47public interface OutputService {
48
buchgr7b515522019-03-29 04:42:17 -070049 /** Properties of the action file system implementation provided by this output service. */
50 enum ActionFileSystemType {
51
52 /** Action file system is disabled */
53 DISABLED,
54
55 /**
56 * The action file system implementation does not take over the output base but complements the
57 * file system by being able to stage remote outputs accessed as inputs by local actions, as
58 * used by Bazel.
59 */
60 STAGE_REMOTE_FILES,
61
62 /**
63 * The action file system implementation is fully featured in-memory file system implementation
64 * and takes full control of the output base, as used by Blaze.
65 */
66 IN_MEMORY_FILE_SYSTEM;
67
68 public boolean inMemoryFileSystem() {
69 return this == IN_MEMORY_FILE_SYSTEM;
70 }
71
72 public boolean isEnabled() {
73 return this != DISABLED;
74 }
75 }
76
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010077 /**
78 * @return the name of filesystem, akin to what you might see in /proc/mounts
79 */
80 String getFilesSystemName();
81
82 /**
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010083 * Start the build.
84 *
Eric Fellheimer2db6a742015-04-28 21:38:43 +000085 * @param buildId the UUID build identifier
Eric Fellheimer1246eb32015-11-18 15:41:38 +000086 * @param finalizeActions whether this build is finalizing actions so that the output service
87 * can track output tree modifications
Eric Fellheimerf3b43af2015-11-13 19:51:20 +000088 * @return a ModifiedFileSet of changed output files.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010089 * @throws BuildFailedException if build preparation failed
90 * @throws InterruptedException
91 */
ulfjack75483b52017-07-11 13:36:41 +020092 ModifiedFileSet startBuild(EventHandler eventHandler, UUID buildId, boolean finalizeActions)
Eric Fellheimer2db6a742015-04-28 21:38:43 +000093 throws BuildFailedException, AbruptExitException, InterruptedException;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010094
95 /**
96 * Finish the build.
97 *
98 * @param buildSuccessful iff build was successful
99 * @throws BuildFailedException on failure
100 */
Rumou Duan2756c022016-10-06 15:57:36 +0000101 void finalizeBuild(boolean buildSuccessful)
102 throws BuildFailedException, AbruptExitException, InterruptedException;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100103
Eric Fellheimerf3b43af2015-11-13 19:51:20 +0000104 /** Notify the output service of a completed action. */
105 void finalizeAction(Action action, MetadataHandler metadataHandler)
ulfjack85b07732019-09-20 09:04:55 -0700106 throws IOException, EnvironmentalExecException, InterruptedException;
Eric Fellheimerf3b43af2015-11-13 19:51:20 +0000107
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100108 /**
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100109 * @return the BatchStat instance or null.
110 */
111 BatchStat getBatchStatter();
112
113 /**
114 * @return true iff createSymlinkTree() is available.
115 */
116 boolean canCreateSymlinkTree();
117
118 /**
119 * Creates the symlink tree
120 *
121 * @param inputPath the input manifest
122 * @param outputPath the output manifest
123 * @param filesetTree is true iff we're constructing a Fileset
124 * @param symlinkTreeRoot the symlink tree root, relative to the execRoot
125 * @throws ExecException on failure
126 * @throws InterruptedException
127 */
128 void createSymlinkTree(Path inputPath, Path outputPath, boolean filesetTree,
129 PathFragment symlinkTreeRoot) throws ExecException, InterruptedException;
130
131 /**
132 * Cleans the entire output tree.
133 *
134 * @throws ExecException on failure
135 * @throws InterruptedException
136 */
137 void clean() throws ExecException, InterruptedException;
138
shahane35e8cf2018-06-18 08:14:01 -0700139 /** @return true iff the file actually lives on a remote server */
140 boolean isRemoteFile(Artifact file);
141
buchgr7b515522019-03-29 04:42:17 -0700142 default ActionFileSystemType actionFileSystemType() {
143 return ActionFileSystemType.DISABLED;
shahane35e8cf2018-06-18 08:14:01 -0700144 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100145
146 /**
shahane35e8cf2018-06-18 08:14:01 -0700147 * @param sourceDelegate filesystem for reading source files (excludes output files)
148 * @param execRootFragment absolute path fragment pointing to the execution root
149 * @param relativeOutputPath execution root relative path to output
150 * @param sourceRoots list of directories on the package path (from {@link
151 * com.google.devtools.build.lib.pkgcache.PathPackageLocator})
152 * @param inputArtifactData information about required inputs to the action
shahane35e8cf2018-06-18 08:14:01 -0700153 * @param outputArtifacts required outputs of the action
shahan5b0e0712018-10-17 07:41:03 -0700154 * @param sourceArtifactFactory obtains source artifacts from source exec paths
buchgr7b515522019-03-29 04:42:17 -0700155 * @return an action-scoped filesystem if {@link #supportsActionFileSystem} is not {@code NONE}
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100156 */
shahane35e8cf2018-06-18 08:14:01 -0700157 @Nullable
158 default FileSystem createActionFileSystem(
159 FileSystem sourceDelegate,
160 PathFragment execRootFragment,
161 String relativeOutputPath,
162 ImmutableList<Root> sourceRoots,
163 ActionInputMap inputArtifactData,
shahan5b0e0712018-10-17 07:41:03 -0700164 Iterable<Artifact> outputArtifacts,
165 Function<PathFragment, SourceArtifact> sourceArtifactFactory) {
shahane35e8cf2018-06-18 08:14:01 -0700166 return null;
167 }
168
169 /**
tomlu880508c2018-08-03 11:21:29 -0700170 * Updates the context used by the filesystem returned by {@link #createActionFileSystem}.
shahane35e8cf2018-06-18 08:14:01 -0700171 *
172 * <p>Should be called as context changes throughout action execution.
173 *
tomlu880508c2018-08-03 11:21:29 -0700174 * @param actionFileSystem must be a filesystem returned by {@link #createActionFileSystem}.
felly943a9c72018-08-09 12:55:47 -0700175 * @param filesets The Fileset symlinks known for this action.
shahane35e8cf2018-06-18 08:14:01 -0700176 */
177 default void updateActionFileSystemContext(
tomlu73eccc22018-09-06 08:02:37 -0700178 FileSystem actionFileSystem,
179 Environment env,
180 MetadataConsumer consumer,
181 ImmutableMap<Artifact, ImmutableList<FilesetOutputSymlink>> filesets)
felly943a9c72018-08-09 12:55:47 -0700182 throws IOException {}
tomlu880508c2018-08-03 11:21:29 -0700183
184 default boolean supportsPathResolverForArtifactValues() {
185 return false;
186 }
187
188 default ArtifactPathResolver createPathResolverForArtifactValues(
189 PathFragment execRoot,
felly2765ca42018-12-28 13:38:55 -0800190 String relativeOutputPath,
tomlu880508c2018-08-03 11:21:29 -0700191 FileSystem fileSystem,
192 ImmutableList<Root> pathEntries,
tomlufe1dd882018-08-15 12:17:42 -0700193 ActionInputMap actionInputMap,
felly5d5da7a2019-01-11 10:59:20 -0800194 Map<Artifact, Collection<Artifact>> expandedArtifacts,
fellyf6408d62019-07-16 12:51:14 -0700195 Map<Artifact, ImmutableList<FilesetOutputSymlink>> filesets)
196 throws IOException {
tomlu880508c2018-08-03 11:21:29 -0700197 throw new IllegalStateException("Path resolver not supported by this class");
198 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100199}