Damien Martin-Guillerez | f88f4d8 | 2015-09-25 13:56:55 +0000 | [diff] [blame] | 1 | // Copyright 2014 The Bazel Authors. All rights reserved. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 2 | // |
| 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 | |
| 15 | package com.google.devtools.build.lib.actions; |
| 16 | |
tomlu | a155b53 | 2017-11-08 20:12:47 +0100 | [diff] [blame] | 17 | import com.google.common.base.Preconditions; |
kush | 2ce45a2 | 2018-05-02 14:15:37 -0700 | [diff] [blame] | 18 | import com.google.common.collect.ImmutableList; |
Klaus Aehlig | d2fcd9d | 2016-08-26 08:16:25 +0000 | [diff] [blame] | 19 | import com.google.common.collect.ImmutableMap; |
ulfjack | 77c9f5e | 2017-06-19 14:17:52 +0200 | [diff] [blame] | 20 | import com.google.common.eventbus.EventBus; |
Michael Thvedt | 434e68e | 2016-02-09 00:57:46 +0000 | [diff] [blame] | 21 | import com.google.devtools.build.lib.actions.Artifact.ArtifactExpander; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 22 | import com.google.devtools.build.lib.actions.cache.MetadataHandler; |
philwo | 3bcb9f6 | 2017-09-06 12:52:21 +0200 | [diff] [blame] | 23 | import com.google.devtools.build.lib.clock.Clock; |
ulfjack | 77c9f5e | 2017-06-19 14:17:52 +0200 | [diff] [blame] | 24 | import com.google.devtools.build.lib.cmdline.Label; |
| 25 | import com.google.devtools.build.lib.events.Event; |
ulfjack | 77c9f5e | 2017-06-19 14:17:52 +0200 | [diff] [blame] | 26 | import com.google.devtools.build.lib.events.EventKind; |
Benjamin Peterson | 1bbeadc | 2018-04-26 05:27:10 -0700 | [diff] [blame] | 27 | import com.google.devtools.build.lib.events.ExtendedEventHandler; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 28 | import com.google.devtools.build.lib.util.io.FileOutErr; |
tomlu | f903eb5 | 2017-10-27 12:12:11 -0400 | [diff] [blame] | 29 | import com.google.devtools.build.lib.vfs.FileSystem; |
ulfjack | 77c9f5e | 2017-06-19 14:17:52 +0200 | [diff] [blame] | 30 | import com.google.devtools.build.lib.vfs.Path; |
kush | 2ce45a2 | 2018-05-02 14:15:37 -0700 | [diff] [blame] | 31 | import com.google.devtools.build.lib.vfs.PathFragment; |
shahan | b1dd4e3 | 2018-05-09 08:23:31 -0700 | [diff] [blame] | 32 | import com.google.devtools.build.lib.vfs.Root; |
Janak Ramakrishnan | 29c5ab4 | 2015-05-14 19:38:12 +0000 | [diff] [blame] | 33 | import com.google.devtools.build.skyframe.SkyFunction; |
| 34 | import com.google.devtools.build.skyframe.SkyFunction.Environment; |
ulfjack | 77c9f5e | 2017-06-19 14:17:52 +0200 | [diff] [blame] | 35 | import com.google.devtools.common.options.OptionsClassProvider; |
ulfjack | 1a328e3 | 2017-04-06 10:25:16 +0000 | [diff] [blame] | 36 | import java.io.Closeable; |
| 37 | import java.io.IOException; |
Klaus Aehlig | d2fcd9d | 2016-08-26 08:16:25 +0000 | [diff] [blame] | 38 | import java.util.Map; |
Janak Ramakrishnan | 29c5ab4 | 2015-05-14 19:38:12 +0000 | [diff] [blame] | 39 | import javax.annotation.Nullable; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 40 | |
| 41 | /** |
| 42 | * A class that groups services in the scope of the action. Like the FileOutErr object. |
| 43 | */ |
ulfjack | 1a328e3 | 2017-04-06 10:25:16 +0000 | [diff] [blame] | 44 | public class ActionExecutionContext implements Closeable { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 45 | |
ahumesky | be31bb8 | 2018-07-26 13:37:45 -0700 | [diff] [blame] | 46 | /** Enum for --subcommands flag */ |
| 47 | public enum ShowSubcommands { |
| 48 | TRUE(true, false), PRETTY_PRINT(true, true), FALSE(false, false); |
| 49 | |
| 50 | private final boolean shouldShowSubcommands; |
| 51 | private final boolean prettyPrintArgs; |
| 52 | |
| 53 | private ShowSubcommands(boolean shouldShowSubcommands, boolean prettyPrintArgs) { |
| 54 | this.shouldShowSubcommands = shouldShowSubcommands; |
| 55 | this.prettyPrintArgs = prettyPrintArgs; |
| 56 | } |
| 57 | } |
| 58 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 59 | private final Executor executor; |
shahan | 499503b | 2018-06-07 18:57:07 -0700 | [diff] [blame] | 60 | private final MetadataProvider actionInputFileCache; |
ulfjack | 7599a4d | 2017-07-21 13:58:33 +0200 | [diff] [blame] | 61 | private final ActionInputPrefetcher actionInputPrefetcher; |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 62 | private final ActionKeyContext actionKeyContext; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 63 | private final MetadataHandler metadataHandler; |
| 64 | private final FileOutErr fileOutErr; |
Klaus Aehlig | d2fcd9d | 2016-08-26 08:16:25 +0000 | [diff] [blame] | 65 | private final ImmutableMap<String, String> clientEnv; |
kush | 2ce45a2 | 2018-05-02 14:15:37 -0700 | [diff] [blame] | 66 | private final ImmutableMap<PathFragment, ImmutableList<FilesetOutputSymlink>> |
| 67 | inputFilesetMappings; |
shahan | b1dd4e3 | 2018-05-09 08:23:31 -0700 | [diff] [blame] | 68 | @Nullable private final ArtifactExpander artifactExpander; |
| 69 | @Nullable private final Environment env; |
| 70 | |
| 71 | @Nullable private final FileSystem actionFileSystem; |
felly | 39974a4 | 2018-08-09 14:28:14 -0700 | [diff] [blame^] | 72 | @Nullable private final Object skyframeDepsResult; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 73 | |
kush | 2ce45a2 | 2018-05-02 14:15:37 -0700 | [diff] [blame] | 74 | @Nullable private ImmutableList<FilesetOutputSymlink> outputSymlinks; |
| 75 | |
felly | d3d8644 | 2018-06-08 18:29:43 -0700 | [diff] [blame] | 76 | private final ArtifactPathResolver pathResolver; |
| 77 | |
Klaus Aehlig | d2fcd9d | 2016-08-26 08:16:25 +0000 | [diff] [blame] | 78 | private ActionExecutionContext( |
| 79 | Executor executor, |
shahan | 499503b | 2018-06-07 18:57:07 -0700 | [diff] [blame] | 80 | MetadataProvider actionInputFileCache, |
ulfjack | 7599a4d | 2017-07-21 13:58:33 +0200 | [diff] [blame] | 81 | ActionInputPrefetcher actionInputPrefetcher, |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 82 | ActionKeyContext actionKeyContext, |
Klaus Aehlig | d2fcd9d | 2016-08-26 08:16:25 +0000 | [diff] [blame] | 83 | MetadataHandler metadataHandler, |
| 84 | FileOutErr fileOutErr, |
| 85 | Map<String, String> clientEnv, |
kush | 2ce45a2 | 2018-05-02 14:15:37 -0700 | [diff] [blame] | 86 | ImmutableMap<PathFragment, ImmutableList<FilesetOutputSymlink>> inputFilesetMappings, |
Michael Thvedt | 434e68e | 2016-02-09 00:57:46 +0000 | [diff] [blame] | 87 | @Nullable ArtifactExpander artifactExpander, |
shahan | b1dd4e3 | 2018-05-09 08:23:31 -0700 | [diff] [blame] | 88 | @Nullable SkyFunction.Environment env, |
felly | 39974a4 | 2018-08-09 14:28:14 -0700 | [diff] [blame^] | 89 | @Nullable FileSystem actionFileSystem, |
| 90 | @Nullable Object skyframeDepsResult) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 91 | this.actionInputFileCache = actionInputFileCache; |
ulfjack | 7599a4d | 2017-07-21 13:58:33 +0200 | [diff] [blame] | 92 | this.actionInputPrefetcher = actionInputPrefetcher; |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 93 | this.actionKeyContext = actionKeyContext; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 94 | this.metadataHandler = metadataHandler; |
| 95 | this.fileOutErr = fileOutErr; |
Klaus Aehlig | d2fcd9d | 2016-08-26 08:16:25 +0000 | [diff] [blame] | 96 | this.clientEnv = ImmutableMap.copyOf(clientEnv); |
kush | 2ce45a2 | 2018-05-02 14:15:37 -0700 | [diff] [blame] | 97 | this.inputFilesetMappings = inputFilesetMappings; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 98 | this.executor = executor; |
Michael Thvedt | 434e68e | 2016-02-09 00:57:46 +0000 | [diff] [blame] | 99 | this.artifactExpander = artifactExpander; |
Janak Ramakrishnan | 29c5ab4 | 2015-05-14 19:38:12 +0000 | [diff] [blame] | 100 | this.env = env; |
shahan | b1dd4e3 | 2018-05-09 08:23:31 -0700 | [diff] [blame] | 101 | this.actionFileSystem = actionFileSystem; |
felly | 39974a4 | 2018-08-09 14:28:14 -0700 | [diff] [blame^] | 102 | this.skyframeDepsResult = skyframeDepsResult; |
felly | fc83d75 | 2018-06-13 14:57:29 -0700 | [diff] [blame] | 103 | this.pathResolver = ArtifactPathResolver.createPathResolver(actionFileSystem, |
felly | d3d8644 | 2018-06-08 18:29:43 -0700 | [diff] [blame] | 104 | // executor is only ever null in testing. |
| 105 | executor == null ? null : executor.getExecRoot()); |
Janak Ramakrishnan | 29c5ab4 | 2015-05-14 19:38:12 +0000 | [diff] [blame] | 106 | } |
| 107 | |
Klaus Aehlig | d2fcd9d | 2016-08-26 08:16:25 +0000 | [diff] [blame] | 108 | public ActionExecutionContext( |
| 109 | Executor executor, |
shahan | 499503b | 2018-06-07 18:57:07 -0700 | [diff] [blame] | 110 | MetadataProvider actionInputFileCache, |
ulfjack | 7599a4d | 2017-07-21 13:58:33 +0200 | [diff] [blame] | 111 | ActionInputPrefetcher actionInputPrefetcher, |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 112 | ActionKeyContext actionKeyContext, |
Klaus Aehlig | d2fcd9d | 2016-08-26 08:16:25 +0000 | [diff] [blame] | 113 | MetadataHandler metadataHandler, |
| 114 | FileOutErr fileOutErr, |
| 115 | Map<String, String> clientEnv, |
kush | 2ce45a2 | 2018-05-02 14:15:37 -0700 | [diff] [blame] | 116 | ImmutableMap<PathFragment, ImmutableList<FilesetOutputSymlink>> inputFilesetMappings, |
shahan | b1dd4e3 | 2018-05-09 08:23:31 -0700 | [diff] [blame] | 117 | ArtifactExpander artifactExpander, |
felly | 39974a4 | 2018-08-09 14:28:14 -0700 | [diff] [blame^] | 118 | @Nullable FileSystem actionFileSystem, |
| 119 | @Nullable Object skyframeDepsResult) { |
Klaus Aehlig | d2fcd9d | 2016-08-26 08:16:25 +0000 | [diff] [blame] | 120 | this( |
| 121 | executor, |
| 122 | actionInputFileCache, |
ulfjack | 7599a4d | 2017-07-21 13:58:33 +0200 | [diff] [blame] | 123 | actionInputPrefetcher, |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 124 | actionKeyContext, |
Klaus Aehlig | d2fcd9d | 2016-08-26 08:16:25 +0000 | [diff] [blame] | 125 | metadataHandler, |
| 126 | fileOutErr, |
| 127 | clientEnv, |
kush | 2ce45a2 | 2018-05-02 14:15:37 -0700 | [diff] [blame] | 128 | inputFilesetMappings, |
Klaus Aehlig | d2fcd9d | 2016-08-26 08:16:25 +0000 | [diff] [blame] | 129 | artifactExpander, |
shahan | b1dd4e3 | 2018-05-09 08:23:31 -0700 | [diff] [blame] | 130 | /*env=*/ null, |
felly | 39974a4 | 2018-08-09 14:28:14 -0700 | [diff] [blame^] | 131 | actionFileSystem, |
| 132 | skyframeDepsResult); |
Janak Ramakrishnan | 29c5ab4 | 2015-05-14 19:38:12 +0000 | [diff] [blame] | 133 | } |
| 134 | |
Klaus Aehlig | d2fcd9d | 2016-08-26 08:16:25 +0000 | [diff] [blame] | 135 | public static ActionExecutionContext forInputDiscovery( |
| 136 | Executor executor, |
shahan | 499503b | 2018-06-07 18:57:07 -0700 | [diff] [blame] | 137 | MetadataProvider actionInputFileCache, |
ulfjack | 7599a4d | 2017-07-21 13:58:33 +0200 | [diff] [blame] | 138 | ActionInputPrefetcher actionInputPrefetcher, |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 139 | ActionKeyContext actionKeyContext, |
Klaus Aehlig | d2fcd9d | 2016-08-26 08:16:25 +0000 | [diff] [blame] | 140 | MetadataHandler metadataHandler, |
| 141 | FileOutErr fileOutErr, |
| 142 | Map<String, String> clientEnv, |
shahan | b1dd4e3 | 2018-05-09 08:23:31 -0700 | [diff] [blame] | 143 | Environment env, |
| 144 | @Nullable FileSystem actionFileSystem) { |
Klaus Aehlig | d2fcd9d | 2016-08-26 08:16:25 +0000 | [diff] [blame] | 145 | return new ActionExecutionContext( |
ulfjack | 7599a4d | 2017-07-21 13:58:33 +0200 | [diff] [blame] | 146 | executor, |
| 147 | actionInputFileCache, |
| 148 | actionInputPrefetcher, |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 149 | actionKeyContext, |
ulfjack | 7599a4d | 2017-07-21 13:58:33 +0200 | [diff] [blame] | 150 | metadataHandler, |
| 151 | fileOutErr, |
| 152 | clientEnv, |
kush | 2ce45a2 | 2018-05-02 14:15:37 -0700 | [diff] [blame] | 153 | ImmutableMap.of(), |
shahan | b1dd4e3 | 2018-05-09 08:23:31 -0700 | [diff] [blame] | 154 | /*artifactExpander=*/ null, |
| 155 | env, |
felly | 39974a4 | 2018-08-09 14:28:14 -0700 | [diff] [blame^] | 156 | actionFileSystem, |
| 157 | /*skyframeDepsResult=*/ null); |
ulfjack | 7599a4d | 2017-07-21 13:58:33 +0200 | [diff] [blame] | 158 | } |
| 159 | |
| 160 | public ActionInputPrefetcher getActionInputPrefetcher() { |
| 161 | return actionInputPrefetcher; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 162 | } |
| 163 | |
shahan | 499503b | 2018-06-07 18:57:07 -0700 | [diff] [blame] | 164 | public MetadataProvider getMetadataProvider() { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 165 | return actionInputFileCache; |
| 166 | } |
| 167 | |
| 168 | public MetadataHandler getMetadataHandler() { |
| 169 | return metadataHandler; |
| 170 | } |
| 171 | |
tomlu | f903eb5 | 2017-10-27 12:12:11 -0400 | [diff] [blame] | 172 | public FileSystem getFileSystem() { |
felly | 7fd3b00 | 2018-05-24 15:03:40 -0700 | [diff] [blame] | 173 | if (actionFileSystem != null) { |
| 174 | return actionFileSystem; |
| 175 | } |
tomlu | f903eb5 | 2017-10-27 12:12:11 -0400 | [diff] [blame] | 176 | return executor.getFileSystem(); |
| 177 | } |
| 178 | |
ulfjack | 77c9f5e | 2017-06-19 14:17:52 +0200 | [diff] [blame] | 179 | public Path getExecRoot() { |
felly | 7fd3b00 | 2018-05-24 15:03:40 -0700 | [diff] [blame] | 180 | return actionFileSystem != null |
| 181 | ? actionFileSystem.getPath(executor.getExecRoot().asFragment()) |
| 182 | : executor.getExecRoot(); |
ulfjack | 77c9f5e | 2017-06-19 14:17:52 +0200 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | /** |
shahan | 18726b7 | 2018-03-15 14:18:46 -0700 | [diff] [blame] | 186 | * Returns the path for an ActionInput. |
| 187 | * |
| 188 | * <p>Notably, in the future, we want any action-scoped artifacts to resolve paths using this |
| 189 | * method instead of {@link Artifact#getPath} because that does not allow filesystem injection. |
| 190 | * |
shahan | b1dd4e3 | 2018-05-09 08:23:31 -0700 | [diff] [blame] | 191 | * <p>TODO(shahan): cleanup {@link Action}-scoped references to {@link Artifact.getPath} and |
| 192 | * {@link Artifact.getRoot}. |
shahan | 18726b7 | 2018-03-15 14:18:46 -0700 | [diff] [blame] | 193 | */ |
| 194 | public Path getInputPath(ActionInput input) { |
felly | d3d8644 | 2018-06-08 18:29:43 -0700 | [diff] [blame] | 195 | return pathResolver.toPath(input); |
shahan | 18726b7 | 2018-03-15 14:18:46 -0700 | [diff] [blame] | 196 | } |
| 197 | |
shahan | b1dd4e3 | 2018-05-09 08:23:31 -0700 | [diff] [blame] | 198 | public Root getRoot(Artifact artifact) { |
felly | d3d8644 | 2018-06-08 18:29:43 -0700 | [diff] [blame] | 199 | return pathResolver.transformRoot(artifact.getRoot().getRoot()); |
| 200 | } |
| 201 | |
felly | d3d8644 | 2018-06-08 18:29:43 -0700 | [diff] [blame] | 202 | public ArtifactPathResolver getPathResolver() { |
| 203 | return pathResolver; |
shahan | b1dd4e3 | 2018-05-09 08:23:31 -0700 | [diff] [blame] | 204 | } |
| 205 | |
shahan | 18726b7 | 2018-03-15 14:18:46 -0700 | [diff] [blame] | 206 | /** |
ulfjack | 77c9f5e | 2017-06-19 14:17:52 +0200 | [diff] [blame] | 207 | * Returns whether failures should have verbose error messages. |
| 208 | */ |
| 209 | public boolean getVerboseFailures() { |
| 210 | return executor.getVerboseFailures(); |
| 211 | } |
| 212 | |
| 213 | /** |
| 214 | * Returns the command line options of the Blaze command being executed. |
| 215 | */ |
| 216 | public OptionsClassProvider getOptions() { |
| 217 | return executor.getOptions(); |
| 218 | } |
| 219 | |
| 220 | public Clock getClock() { |
| 221 | return executor.getClock(); |
| 222 | } |
| 223 | |
| 224 | public EventBus getEventBus() { |
| 225 | return executor.getEventBus(); |
| 226 | } |
| 227 | |
Benjamin Peterson | 1bbeadc | 2018-04-26 05:27:10 -0700 | [diff] [blame] | 228 | public ExtendedEventHandler getEventHandler() { |
ulfjack | 77c9f5e | 2017-06-19 14:17:52 +0200 | [diff] [blame] | 229 | return executor.getEventHandler(); |
| 230 | } |
| 231 | |
kush | 2ce45a2 | 2018-05-02 14:15:37 -0700 | [diff] [blame] | 232 | public ImmutableMap<PathFragment, ImmutableList<FilesetOutputSymlink>> getInputFilesetMappings() { |
| 233 | return inputFilesetMappings; |
| 234 | } |
| 235 | |
| 236 | @Nullable |
| 237 | public ImmutableList<FilesetOutputSymlink> getOutputSymlinks() { |
| 238 | return outputSymlinks; |
| 239 | } |
| 240 | |
| 241 | public void setOutputSymlinks(ImmutableList<FilesetOutputSymlink> outputSymlinks) { |
| 242 | Preconditions.checkState( |
| 243 | this.outputSymlinks == null, |
| 244 | "Unexpected reassignment of the outputSymlinks of a Fileset from\n:%s to:\n%s", |
| 245 | this.outputSymlinks, |
| 246 | outputSymlinks); |
| 247 | this.outputSymlinks = outputSymlinks; |
| 248 | } |
| 249 | |
ulfjack | 77c9f5e | 2017-06-19 14:17:52 +0200 | [diff] [blame] | 250 | /** |
| 251 | * Looks up and returns an action context implementation of the given interface type. |
| 252 | */ |
| 253 | public <T extends ActionContext> T getContext(Class<? extends T> type) { |
| 254 | return executor.getContext(type); |
| 255 | } |
| 256 | |
ulfjack | 77c9f5e | 2017-06-19 14:17:52 +0200 | [diff] [blame] | 257 | /** |
ulfjack | 77c9f5e | 2017-06-19 14:17:52 +0200 | [diff] [blame] | 258 | * Report a subcommand event to this Executor's Reporter and, if action |
| 259 | * logging is enabled, post it on its EventBus. |
| 260 | */ |
ahumesky | be31bb8 | 2018-07-26 13:37:45 -0700 | [diff] [blame] | 261 | public void maybeReportSubcommand(Spawn spawn) { |
| 262 | ShowSubcommands showSubcommands = executor.reportsSubcommands(); |
| 263 | if (!showSubcommands.shouldShowSubcommands) { |
| 264 | return; |
| 265 | } |
| 266 | |
ulfjack | 77c9f5e | 2017-06-19 14:17:52 +0200 | [diff] [blame] | 267 | String reason; |
| 268 | ActionOwner owner = spawn.getResourceOwner().getOwner(); |
| 269 | if (owner == null) { |
| 270 | reason = spawn.getResourceOwner().prettyPrint(); |
| 271 | } else { |
| 272 | reason = Label.print(owner.getLabel()) |
| 273 | + " [" + spawn.getResourceOwner().prettyPrint() + "]"; |
| 274 | } |
ahumesky | be31bb8 | 2018-07-26 13:37:45 -0700 | [diff] [blame] | 275 | String message = Spawns.asShellCommand(spawn, getExecRoot(), showSubcommands.prettyPrintArgs); |
ulfjack | 77c9f5e | 2017-06-19 14:17:52 +0200 | [diff] [blame] | 276 | getEventHandler().handle(Event.of(EventKind.SUBCOMMAND, null, "# " + reason + "\n" + message)); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 277 | } |
| 278 | |
Klaus Aehlig | 4c10f3f | 2016-08-26 15:58:48 +0000 | [diff] [blame] | 279 | public ImmutableMap<String, String> getClientEnv() { |
| 280 | return clientEnv; |
| 281 | } |
| 282 | |
Michael Thvedt | 434e68e | 2016-02-09 00:57:46 +0000 | [diff] [blame] | 283 | public ArtifactExpander getArtifactExpander() { |
| 284 | return artifactExpander; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 285 | } |
| 286 | |
felly | 39974a4 | 2018-08-09 14:28:14 -0700 | [diff] [blame^] | 287 | @Nullable |
| 288 | public Object getSkyframeDepsResult() { |
| 289 | return skyframeDepsResult; |
| 290 | } |
| 291 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 292 | /** |
| 293 | * Provide that {@code FileOutErr} that the action should use for redirecting the output and error |
| 294 | * stream. |
| 295 | */ |
| 296 | public FileOutErr getFileOutErr() { |
| 297 | return fileOutErr; |
| 298 | } |
| 299 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 300 | /** |
Janak Ramakrishnan | 29c5ab4 | 2015-05-14 19:38:12 +0000 | [diff] [blame] | 301 | * Provides a mechanism for the action to request values from Skyframe while it discovers inputs. |
| 302 | */ |
| 303 | public Environment getEnvironmentForDiscoveringInputs() { |
| 304 | return Preconditions.checkNotNull(env); |
| 305 | } |
| 306 | |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 307 | public ActionKeyContext getActionKeyContext() { |
| 308 | return actionKeyContext; |
| 309 | } |
| 310 | |
ulfjack | 1a328e3 | 2017-04-06 10:25:16 +0000 | [diff] [blame] | 311 | @Override |
| 312 | public void close() throws IOException { |
| 313 | fileOutErr.close(); |
| 314 | } |
| 315 | |
Janak Ramakrishnan | 29c5ab4 | 2015-05-14 19:38:12 +0000 | [diff] [blame] | 316 | /** |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 317 | * Allows us to create a new context that overrides the FileOutErr with another one. This is |
| 318 | * useful for muting the output for example. |
| 319 | */ |
| 320 | public ActionExecutionContext withFileOutErr(FileOutErr fileOutErr) { |
Klaus Aehlig | d2fcd9d | 2016-08-26 08:16:25 +0000 | [diff] [blame] | 321 | return new ActionExecutionContext( |
| 322 | executor, |
| 323 | actionInputFileCache, |
ulfjack | 7599a4d | 2017-07-21 13:58:33 +0200 | [diff] [blame] | 324 | actionInputPrefetcher, |
tomlu | 3d1a194 | 2017-11-29 14:01:21 -0800 | [diff] [blame] | 325 | actionKeyContext, |
Klaus Aehlig | d2fcd9d | 2016-08-26 08:16:25 +0000 | [diff] [blame] | 326 | metadataHandler, |
| 327 | fileOutErr, |
| 328 | clientEnv, |
kush | 2ce45a2 | 2018-05-02 14:15:37 -0700 | [diff] [blame] | 329 | inputFilesetMappings, |
Klaus Aehlig | d2fcd9d | 2016-08-26 08:16:25 +0000 | [diff] [blame] | 330 | artifactExpander, |
shahan | b1dd4e3 | 2018-05-09 08:23:31 -0700 | [diff] [blame] | 331 | env, |
felly | 39974a4 | 2018-08-09 14:28:14 -0700 | [diff] [blame^] | 332 | actionFileSystem, |
| 333 | skyframeDepsResult); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 334 | } |
| 335 | } |