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.analysis; |
| 16 | |
| 17 | import com.google.common.annotations.VisibleForTesting; |
| 18 | import com.google.common.collect.ImmutableCollection; |
| 19 | import com.google.common.collect.ImmutableList; |
| 20 | import com.google.common.collect.ImmutableMap; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 21 | import com.google.common.collect.Iterables; |
| 22 | import com.google.common.collect.Sets; |
| 23 | import com.google.devtools.build.lib.actions.Artifact; |
| 24 | import com.google.devtools.build.lib.actions.BaseSpawn; |
| 25 | import com.google.devtools.build.lib.analysis.actions.FileWriteAction; |
Lukacs Berki | 6e91eb9 | 2015-09-21 09:12:37 +0000 | [diff] [blame] | 26 | import com.google.devtools.build.lib.cmdline.Label; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 27 | import com.google.devtools.build.lib.collect.nestedset.NestedSetBuilder; |
Lukacs Berki | 7894c18 | 2016-05-10 12:07:01 +0000 | [diff] [blame] | 28 | import com.google.devtools.build.lib.rules.AliasProvider; |
Francois-Rene Rideau | ab049e0 | 2016-02-17 16:13:46 +0000 | [diff] [blame] | 29 | import com.google.devtools.build.lib.syntax.SkylarkDict; |
| 30 | import com.google.devtools.build.lib.syntax.SkylarkList; |
Lukacs Berki | ffa73ad | 2015-09-18 11:40:12 +0000 | [diff] [blame] | 31 | import com.google.devtools.build.lib.syntax.Type; |
Dmitry Lomov | 82434eb | 2016-01-29 12:35:12 +0000 | [diff] [blame] | 32 | import com.google.devtools.build.lib.util.OS; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 33 | import com.google.devtools.build.lib.util.Pair; |
| 34 | import com.google.devtools.build.lib.vfs.PathFragment; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 35 | import java.util.Collection; |
| 36 | import java.util.HashMap; |
| 37 | import java.util.List; |
| 38 | import java.util.Map; |
| 39 | import java.util.Map.Entry; |
Francois-Rene Rideau | 79be96f | 2015-10-07 19:25:38 +0000 | [diff] [blame] | 40 | import javax.annotation.Nullable; |
| 41 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 42 | /** |
| 43 | * Provides shared functionality for parameterized command-line launching |
| 44 | * e.g. {@link com.google.devtools.build.lib.view.genrule.GenRule} |
| 45 | * Also used by {@link com.google.devtools.build.lib.rules.extra.ExtraActionFactory}. |
| 46 | * |
| 47 | * Two largely independent separate sets of functionality are provided: |
| 48 | * 1- string interpolation for {@code $(location[s] ...)} and {@code $(MakeVariable)} |
| 49 | * 2- a utility to build potentially large command lines (presumably made of multiple commands), |
| 50 | * that if presumed too large for the kernel's taste can be dumped into a shell script |
| 51 | * that will contain the same commands, |
| 52 | * at which point the shell script is added to the list of inputs. |
| 53 | */ |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 54 | public final class CommandHelper { |
| 55 | |
| 56 | /** |
| 57 | * Maximum total command-line length, in bytes, not counting "/bin/bash -c ". |
| 58 | * If the command is very long, then we write the command to a script file, |
| 59 | * to avoid overflowing any limits on command-line length. |
| 60 | * For short commands, we just use /bin/bash -c command. |
Dmitry Lomov | 82434eb | 2016-01-29 12:35:12 +0000 | [diff] [blame] | 61 | * |
| 62 | * Maximum command line length on Windows is 32767[1], but for cmd.exe it is 8192[2]. |
| 63 | * [1] https://msdn.microsoft.com/en-us/library/ms682425(VS.85).aspx |
| 64 | * [2] https://support.microsoft.com/en-us/kb/830473. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 65 | */ |
| 66 | @VisibleForTesting |
Dmitry Lomov | 82434eb | 2016-01-29 12:35:12 +0000 | [diff] [blame] | 67 | public static int maxCommandLength = OS.getCurrent() == OS.WINDOWS ? 8000 : 64000; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 68 | |
| 69 | /** |
| 70 | * A map of remote path prefixes and corresponding runfiles manifests for tools |
| 71 | * used by this rule. |
| 72 | */ |
Francois-Rene Rideau | ab049e0 | 2016-02-17 16:13:46 +0000 | [diff] [blame] | 73 | private final SkylarkDict<PathFragment, Artifact> remoteRunfileManifestMap; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 74 | |
| 75 | /** |
| 76 | * Use labelMap for heuristically expanding labels (does not include "outs") |
| 77 | * This is similar to heuristic location expansion in LocationExpander |
| 78 | * and should be kept in sync. |
| 79 | */ |
Francois-Rene Rideau | ab049e0 | 2016-02-17 16:13:46 +0000 | [diff] [blame] | 80 | private final SkylarkDict<Label, ImmutableCollection<Artifact>> labelMap; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 81 | |
| 82 | /** |
| 83 | * The ruleContext this helper works on |
| 84 | */ |
| 85 | private final RuleContext ruleContext; |
| 86 | |
| 87 | /** |
| 88 | * Output executable files from the 'tools' attribute. |
| 89 | */ |
Francois-Rene Rideau | ab049e0 | 2016-02-17 16:13:46 +0000 | [diff] [blame] | 90 | private final SkylarkList<Artifact> resolvedTools; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 91 | |
| 92 | /** |
Googler | f49bb0c | 2015-02-11 16:18:28 +0000 | [diff] [blame] | 93 | * Creates a {@link CommandHelper}. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 94 | * |
Googler | f49bb0c | 2015-02-11 16:18:28 +0000 | [diff] [blame] | 95 | * @param tools resolves set of tools into set of executable binaries. Populates manifests, |
| 96 | * remoteRunfiles and label map where required. |
| 97 | * @param labelMap adds files to set of known files of label. Used for resolving $(location) |
| 98 | * variables. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 99 | */ |
Brian Silverman | 53c3ce1 | 2015-08-28 09:17:14 +0000 | [diff] [blame] | 100 | public CommandHelper( |
| 101 | RuleContext ruleContext, |
| 102 | Iterable<? extends TransitiveInfoCollection> tools, |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 103 | ImmutableMap<Label, Iterable<Artifact>> labelMap) { |
| 104 | this.ruleContext = ruleContext; |
| 105 | |
| 106 | ImmutableList.Builder<Artifact> resolvedToolsBuilder = ImmutableList.builder(); |
| 107 | ImmutableMap.Builder<PathFragment, Artifact> remoteRunfileManifestBuilder = |
| 108 | ImmutableMap.builder(); |
| 109 | Map<Label, Collection<Artifact>> tempLabelMap = new HashMap<>(); |
| 110 | |
| 111 | for (Map.Entry<Label, Iterable<Artifact>> entry : labelMap.entrySet()) { |
| 112 | Iterables.addAll(mapGet(tempLabelMap, entry.getKey()), entry.getValue()); |
| 113 | } |
| 114 | |
Brian Silverman | 53c3ce1 | 2015-08-28 09:17:14 +0000 | [diff] [blame] | 115 | for (TransitiveInfoCollection dep : tools) { // (Note: host configuration) |
Lukacs Berki | 7894c18 | 2016-05-10 12:07:01 +0000 | [diff] [blame] | 116 | Label label = AliasProvider.getDependencyLabel(dep); |
Brian Silverman | 53c3ce1 | 2015-08-28 09:17:14 +0000 | [diff] [blame] | 117 | FilesToRunProvider tool = dep.getProvider(FilesToRunProvider.class); |
| 118 | if (tool == null) { |
| 119 | continue; |
| 120 | } |
| 121 | |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 122 | Collection<Artifact> files = tool.getFilesToRun(); |
| 123 | resolvedToolsBuilder.addAll(files); |
| 124 | Artifact executableArtifact = tool.getExecutable(); |
| 125 | // If the label has an executable artifact add that to the multimaps. |
| 126 | if (executableArtifact != null) { |
| 127 | mapGet(tempLabelMap, label).add(executableArtifact); |
| 128 | // Also send the runfiles when running remotely. |
| 129 | Artifact runfilesManifest = tool.getRunfilesManifest(); |
| 130 | if (runfilesManifest != null) { |
| 131 | remoteRunfileManifestBuilder.put( |
| 132 | BaseSpawn.runfilesForFragment(executableArtifact.getExecPath()), runfilesManifest); |
| 133 | } |
| 134 | } else { |
| 135 | // Map all depArtifacts to the respective label using the multimaps. |
Ulf Adams | 07dba94 | 2015-03-05 14:47:37 +0000 | [diff] [blame] | 136 | mapGet(tempLabelMap, label).addAll(files); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 137 | } |
| 138 | } |
| 139 | |
Dmitry Lomov | 5fd7da5 | 2016-09-05 09:44:48 +0000 | [diff] [blame] | 140 | this.resolvedTools = SkylarkList.createImmutable(resolvedToolsBuilder.build()); |
Francois-Rene Rideau | ab049e0 | 2016-02-17 16:13:46 +0000 | [diff] [blame] | 141 | this.remoteRunfileManifestMap = SkylarkDict.copyOf(null, remoteRunfileManifestBuilder.build()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 142 | ImmutableMap.Builder<Label, ImmutableCollection<Artifact>> labelMapBuilder = |
| 143 | ImmutableMap.builder(); |
| 144 | for (Entry<Label, Collection<Artifact>> entry : tempLabelMap.entrySet()) { |
| 145 | labelMapBuilder.put(entry.getKey(), ImmutableList.copyOf(entry.getValue())); |
| 146 | } |
Francois-Rene Rideau | ab049e0 | 2016-02-17 16:13:46 +0000 | [diff] [blame] | 147 | this.labelMap = SkylarkDict.copyOf(null, labelMapBuilder.build()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 148 | } |
| 149 | |
Francois-Rene Rideau | ab049e0 | 2016-02-17 16:13:46 +0000 | [diff] [blame] | 150 | public SkylarkList<Artifact> getResolvedTools() { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 151 | return resolvedTools; |
| 152 | } |
| 153 | |
Francois-Rene Rideau | ab049e0 | 2016-02-17 16:13:46 +0000 | [diff] [blame] | 154 | public SkylarkDict<PathFragment, Artifact> getRemoteRunfileManifestMap() { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 155 | return remoteRunfileManifestMap; |
| 156 | } |
| 157 | |
| 158 | // Returns the value in the specified corresponding to 'key', creating and |
| 159 | // inserting an empty container if absent. We use Map not Multimap because |
| 160 | // we need to distinguish the cases of "empty value" and "absent key". |
| 161 | private static Collection<Artifact> mapGet(Map<Label, Collection<Artifact>> map, Label key) { |
| 162 | Collection<Artifact> values = map.get(key); |
| 163 | if (values == null) { |
| 164 | // We use sets not lists, because it's conceivable that the same artifact |
| 165 | // could appear twice, e.g. in "srcs" and "deps". |
| 166 | values = Sets.newHashSet(); |
| 167 | map.put(key, values); |
| 168 | } |
| 169 | return values; |
| 170 | } |
| 171 | |
| 172 | /** |
Francois-Rene Rideau | 79be96f | 2015-10-07 19:25:38 +0000 | [diff] [blame] | 173 | * Resolves a command, and expands known locations for $(location) |
| 174 | * variables. |
| 175 | */ |
| 176 | public String resolveCommandAndExpandLabels( |
| 177 | String command, |
| 178 | @Nullable String attribute, |
| 179 | Boolean supportLegacyExpansion, |
| 180 | Boolean allowDataInLabel) { |
Francois-Rene Rideau | ab049e0 | 2016-02-17 16:13:46 +0000 | [diff] [blame] | 181 | LocationExpander expander = new LocationExpander( |
| 182 | ruleContext, ImmutableMap.copyOf(labelMap), allowDataInLabel); |
Francois-Rene Rideau | 79be96f | 2015-10-07 19:25:38 +0000 | [diff] [blame] | 183 | if (attribute != null) { |
| 184 | command = expander.expandAttribute(attribute, command); |
| 185 | } else { |
| 186 | command = expander.expand(command); |
| 187 | } |
| 188 | if (supportLegacyExpansion) { |
| 189 | command = expandLabels(command, labelMap); |
| 190 | } |
| 191 | return command; |
| 192 | } |
| 193 | |
| 194 | /** |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 195 | * Resolves the 'cmd' attribute, and expands known locations for $(location) |
| 196 | * variables. |
| 197 | */ |
Florian Weikert | 05698b8 | 2015-07-10 09:06:12 +0000 | [diff] [blame] | 198 | public String resolveCommandAndExpandLabels( |
| 199 | Boolean supportLegacyExpansion, Boolean allowDataInLabel) { |
Francois-Rene Rideau | 79be96f | 2015-10-07 19:25:38 +0000 | [diff] [blame] | 200 | return resolveCommandAndExpandLabels( |
| 201 | ruleContext.attributes().get("cmd", Type.STRING), |
| 202 | "cmd", |
| 203 | supportLegacyExpansion, |
| 204 | allowDataInLabel); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 205 | } |
| 206 | |
| 207 | /** |
| 208 | * Expands labels occurring in the string "expr" in the rule 'cmd'. |
| 209 | * Each label must be valid, be a declared prerequisite, and expand to a |
| 210 | * unique path. |
| 211 | * |
| 212 | * <p>If the expansion fails, an attribute error is reported and the original |
| 213 | * expression is returned. |
| 214 | */ |
| 215 | private <T extends Iterable<Artifact>> String expandLabels(String expr, Map<Label, T> labelMap) { |
| 216 | try { |
| 217 | return LabelExpander.expand(expr, labelMap, ruleContext.getLabel()); |
| 218 | } catch (LabelExpander.NotUniqueExpansionException nuee) { |
| 219 | ruleContext.attributeError("cmd", nuee.getMessage()); |
| 220 | return expr; |
| 221 | } |
| 222 | } |
| 223 | |
| 224 | private static Pair<List<String>, Artifact> buildCommandLineMaybeWithScriptFile( |
Googler | f49bb0c | 2015-02-11 16:18:28 +0000 | [diff] [blame] | 225 | RuleContext ruleContext, String command, String scriptPostFix, PathFragment shellPath) { |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 226 | List<String> argv; |
| 227 | Artifact scriptFileArtifact = null; |
| 228 | if (command.length() <= maxCommandLength) { |
Googler | f49bb0c | 2015-02-11 16:18:28 +0000 | [diff] [blame] | 229 | argv = buildCommandLineSimpleArgv(command, shellPath); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 230 | } else { |
| 231 | // Use script file. |
| 232 | scriptFileArtifact = buildCommandLineArtifact(ruleContext, command, scriptPostFix); |
Googler | f49bb0c | 2015-02-11 16:18:28 +0000 | [diff] [blame] | 233 | argv = buildCommandLineArgvWithArtifact(scriptFileArtifact, shellPath); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 234 | } |
| 235 | return Pair.of(argv, scriptFileArtifact); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 236 | } |
| 237 | |
Googler | f49bb0c | 2015-02-11 16:18:28 +0000 | [diff] [blame] | 238 | private static ImmutableList<String> buildCommandLineArgvWithArtifact(Artifact scriptFileArtifact, |
| 239 | PathFragment shellPath) { |
| 240 | return ImmutableList.of(shellPath.getPathString(), scriptFileArtifact.getExecPathString()); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 241 | } |
| 242 | |
| 243 | private static Artifact buildCommandLineArtifact(RuleContext ruleContext, String command, |
| 244 | String scriptPostFix) { |
| 245 | String scriptFileName = ruleContext.getTarget().getName() + scriptPostFix; |
| 246 | String scriptFileContents = "#!/bin/bash\n" + command; |
| 247 | Artifact scriptFileArtifact = FileWriteAction.createFile( |
| 248 | ruleContext, scriptFileName, scriptFileContents, /*executable=*/true); |
| 249 | return scriptFileArtifact; |
| 250 | } |
| 251 | |
Googler | f49bb0c | 2015-02-11 16:18:28 +0000 | [diff] [blame] | 252 | private static ImmutableList<String> buildCommandLineSimpleArgv(String command, |
| 253 | PathFragment shellPath) { |
| 254 | return ImmutableList.of(shellPath.getPathString(), "-c", command); |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 255 | } |
| 256 | |
| 257 | /** |
| 258 | * Builds the set of command-line arguments. Creates a bash script if the |
Googler | f49bb0c | 2015-02-11 16:18:28 +0000 | [diff] [blame] | 259 | * command line is longer than the allowed maximum {@link #maxCommandLength}. |
| 260 | * Fixes up the input artifact list with the created bash script when required. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 261 | */ |
| 262 | public List<String> buildCommandLine( |
| 263 | String command, NestedSetBuilder<Artifact> inputs, String scriptPostFix) { |
Googler | e6402cb | 2015-04-13 14:54:27 +0000 | [diff] [blame] | 264 | return buildCommandLine(command, inputs, scriptPostFix, ImmutableMap.<String, String>of()); |
Googler | f49bb0c | 2015-02-11 16:18:28 +0000 | [diff] [blame] | 265 | } |
| 266 | |
| 267 | /** |
| 268 | * Builds the set of command-line arguments using the specified shell path. Creates a bash script |
| 269 | * if the command line is longer than the allowed maximum {@link #maxCommandLength}. |
| 270 | * Fixes up the input artifact list with the created bash script when required. |
| 271 | * |
Googler | e6402cb | 2015-04-13 14:54:27 +0000 | [diff] [blame] | 272 | * @param executionInfo an execution info map of the action associated with the command line to be |
| 273 | * built. |
Googler | f49bb0c | 2015-02-11 16:18:28 +0000 | [diff] [blame] | 274 | */ |
| 275 | public List<String> buildCommandLine( |
| 276 | String command, NestedSetBuilder<Artifact> inputs, String scriptPostFix, |
Googler | e6402cb | 2015-04-13 14:54:27 +0000 | [diff] [blame] | 277 | Map<String, String> executionInfo) { |
Googler | f49bb0c | 2015-02-11 16:18:28 +0000 | [diff] [blame] | 278 | Pair<List<String>, Artifact> argvAndScriptFile = |
Chris Parsons | 9a9573b | 2016-02-10 21:15:11 +0000 | [diff] [blame] | 279 | buildCommandLineMaybeWithScriptFile(ruleContext, command, scriptPostFix, |
| 280 | shellPath(executionInfo)); |
Googler | f49bb0c | 2015-02-11 16:18:28 +0000 | [diff] [blame] | 281 | if (argvAndScriptFile.second != null) { |
| 282 | inputs.add(argvAndScriptFile.second); |
| 283 | } |
| 284 | return argvAndScriptFile.first; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 285 | } |
| 286 | |
| 287 | /** |
| 288 | * Builds the set of command-line arguments. Creates a bash script if the |
Googler | f49bb0c | 2015-02-11 16:18:28 +0000 | [diff] [blame] | 289 | * command line is longer than the allowed maximum {@link #maxCommandLength}. |
| 290 | * Fixes up the input artifact list with the created bash script when required. |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 291 | */ |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 292 | public List<String> buildCommandLine( |
Chris Parsons | 9a9573b | 2016-02-10 21:15:11 +0000 | [diff] [blame] | 293 | String command, List<Artifact> inputs, String scriptPostFix, |
| 294 | Map<String, String> executionInfo) { |
Googler | f49bb0c | 2015-02-11 16:18:28 +0000 | [diff] [blame] | 295 | Pair<List<String>, Artifact> argvAndScriptFile = buildCommandLineMaybeWithScriptFile( |
Chris Parsons | 9a9573b | 2016-02-10 21:15:11 +0000 | [diff] [blame] | 296 | ruleContext, command, scriptPostFix, shellPath(executionInfo)); |
Googler | f49bb0c | 2015-02-11 16:18:28 +0000 | [diff] [blame] | 297 | if (argvAndScriptFile.second != null) { |
| 298 | inputs.add(argvAndScriptFile.second); |
| 299 | } |
| 300 | return argvAndScriptFile.first; |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 301 | } |
Chris Parsons | 9a9573b | 2016-02-10 21:15:11 +0000 | [diff] [blame] | 302 | |
| 303 | /** |
| 304 | * Returns the path to the shell for an action with the given execution requirements. |
| 305 | */ |
| 306 | private PathFragment shellPath(Map<String, String> executionInfo) { |
| 307 | // Use vanilla /bin/bash for actions running on mac machines. |
| 308 | return executionInfo.containsKey("requires-darwin") |
Lukacs Berki | ae7be6f | 2016-09-21 13:21:56 +0000 | [diff] [blame] | 309 | ? new PathFragment("/bin/bash") : ruleContext.getConfiguration().getShellExecutable(); |
Chris Parsons | 9a9573b | 2016-02-10 21:15:11 +0000 | [diff] [blame] | 310 | } |
Han-Wen Nienhuys | d08b27f | 2015-02-25 16:45:20 +0100 | [diff] [blame] | 311 | } |