blob: 02c68cf48aebb3f8439374a360bacf45dd18b590 [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
49 /**
50 * @return the name of filesystem, akin to what you might see in /proc/mounts
51 */
52 String getFilesSystemName();
53
54 /**
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010055 * Start the build.
56 *
Eric Fellheimer2db6a742015-04-28 21:38:43 +000057 * @param buildId the UUID build identifier
Eric Fellheimer1246eb32015-11-18 15:41:38 +000058 * @param finalizeActions whether this build is finalizing actions so that the output service
59 * can track output tree modifications
Eric Fellheimerf3b43af2015-11-13 19:51:20 +000060 * @return a ModifiedFileSet of changed output files.
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010061 * @throws BuildFailedException if build preparation failed
62 * @throws InterruptedException
63 */
ulfjack75483b52017-07-11 13:36:41 +020064 ModifiedFileSet startBuild(EventHandler eventHandler, UUID buildId, boolean finalizeActions)
Eric Fellheimer2db6a742015-04-28 21:38:43 +000065 throws BuildFailedException, AbruptExitException, InterruptedException;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010066
67 /**
68 * Finish the build.
69 *
70 * @param buildSuccessful iff build was successful
71 * @throws BuildFailedException on failure
72 */
Rumou Duan2756c022016-10-06 15:57:36 +000073 void finalizeBuild(boolean buildSuccessful)
74 throws BuildFailedException, AbruptExitException, InterruptedException;
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010075
Eric Fellheimerf3b43af2015-11-13 19:51:20 +000076 /** Notify the output service of a completed action. */
77 void finalizeAction(Action action, MetadataHandler metadataHandler)
78 throws IOException, EnvironmentalExecException;
79
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010080 /**
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +010081 * @return the BatchStat instance or null.
82 */
83 BatchStat getBatchStatter();
84
85 /**
86 * @return true iff createSymlinkTree() is available.
87 */
88 boolean canCreateSymlinkTree();
89
90 /**
91 * Creates the symlink tree
92 *
93 * @param inputPath the input manifest
94 * @param outputPath the output manifest
95 * @param filesetTree is true iff we're constructing a Fileset
96 * @param symlinkTreeRoot the symlink tree root, relative to the execRoot
97 * @throws ExecException on failure
98 * @throws InterruptedException
99 */
100 void createSymlinkTree(Path inputPath, Path outputPath, boolean filesetTree,
101 PathFragment symlinkTreeRoot) throws ExecException, InterruptedException;
102
103 /**
104 * Cleans the entire output tree.
105 *
106 * @throws ExecException on failure
107 * @throws InterruptedException
108 */
109 void clean() throws ExecException, InterruptedException;
110
shahane35e8cf2018-06-18 08:14:01 -0700111 /** @return true iff the file actually lives on a remote server */
112 boolean isRemoteFile(Artifact file);
113
114 default boolean supportsActionFileSystem() {
115 return false;
116 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100117
118 /**
shahane35e8cf2018-06-18 08:14:01 -0700119 * @param sourceDelegate filesystem for reading source files (excludes output files)
120 * @param execRootFragment absolute path fragment pointing to the execution root
121 * @param relativeOutputPath execution root relative path to output
122 * @param sourceRoots list of directories on the package path (from {@link
123 * com.google.devtools.build.lib.pkgcache.PathPackageLocator})
124 * @param inputArtifactData information about required inputs to the action
shahane35e8cf2018-06-18 08:14:01 -0700125 * @param outputArtifacts required outputs of the action
shahan5b0e0712018-10-17 07:41:03 -0700126 * @param sourceArtifactFactory obtains source artifacts from source exec paths
tomlu880508c2018-08-03 11:21:29 -0700127 * @return an action-scoped filesystem if {@link #supportsActionFileSystem} is true
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100128 */
shahane35e8cf2018-06-18 08:14:01 -0700129 @Nullable
130 default FileSystem createActionFileSystem(
131 FileSystem sourceDelegate,
132 PathFragment execRootFragment,
133 String relativeOutputPath,
134 ImmutableList<Root> sourceRoots,
135 ActionInputMap inputArtifactData,
shahan5b0e0712018-10-17 07:41:03 -0700136 Iterable<Artifact> outputArtifacts,
137 Function<PathFragment, SourceArtifact> sourceArtifactFactory) {
shahane35e8cf2018-06-18 08:14:01 -0700138 return null;
139 }
140
141 /**
tomlu880508c2018-08-03 11:21:29 -0700142 * Updates the context used by the filesystem returned by {@link #createActionFileSystem}.
shahane35e8cf2018-06-18 08:14:01 -0700143 *
144 * <p>Should be called as context changes throughout action execution.
145 *
tomlu880508c2018-08-03 11:21:29 -0700146 * @param actionFileSystem must be a filesystem returned by {@link #createActionFileSystem}.
felly943a9c72018-08-09 12:55:47 -0700147 * @param filesets The Fileset symlinks known for this action.
shahane35e8cf2018-06-18 08:14:01 -0700148 */
149 default void updateActionFileSystemContext(
tomlu73eccc22018-09-06 08:02:37 -0700150 FileSystem actionFileSystem,
151 Environment env,
152 MetadataConsumer consumer,
153 ImmutableMap<Artifact, ImmutableList<FilesetOutputSymlink>> filesets)
felly943a9c72018-08-09 12:55:47 -0700154 throws IOException {}
tomlu880508c2018-08-03 11:21:29 -0700155
156 default boolean supportsPathResolverForArtifactValues() {
157 return false;
158 }
159
160 default ArtifactPathResolver createPathResolverForArtifactValues(
161 PathFragment execRoot,
felly2765ca42018-12-28 13:38:55 -0800162 String relativeOutputPath,
tomlu880508c2018-08-03 11:21:29 -0700163 FileSystem fileSystem,
164 ImmutableList<Root> pathEntries,
tomlufe1dd882018-08-15 12:17:42 -0700165 ActionInputMap actionInputMap,
166 Map<Artifact, Collection<Artifact>> expandedArtifacts) {
tomlu880508c2018-08-03 11:21:29 -0700167 throw new IllegalStateException("Path resolver not supported by this class");
168 }
Han-Wen Nienhuysd08b27f2015-02-25 16:45:20 +0100169}