|
92 | 92 | import com.google.devtools.build.lib.vfs.FileSystemUtils;
|
93 | 93 | import com.google.devtools.build.lib.vfs.Path;
|
94 | 94 | import com.google.devtools.build.lib.vfs.PathFragment;
|
| 95 | +import com.google.devtools.common.options.Converters; |
95 | 96 | import com.google.devtools.common.options.Option;
|
96 | 97 | import com.google.devtools.common.options.OptionDocumentationCategory;
|
97 | 98 | import com.google.devtools.common.options.OptionEffectTag;
|
@@ -164,6 +165,22 @@ public static class RunOptions extends OptionsBase {
|
164 | 165 | "If true, includes paths to replace in ExecRequest to make the resulting paths"
|
165 | 166 | + " portable.")
|
166 | 167 | public boolean portablePaths;
|
| 168 | + |
| 169 | + @Option( |
| 170 | + name = "run_env", |
| 171 | + converter = Converters.OptionalAssignmentConverter.class, |
| 172 | + allowMultiple = true, |
| 173 | + defaultValue = "null", |
| 174 | + documentationCategory = OptionDocumentationCategory.BAZEL_CLIENT_OPTIONS, |
| 175 | + effectTags = {OptionEffectTag.AFFECTS_OUTPUTS}, |
| 176 | + help = |
| 177 | + "Specifies the set of environment variables available to actions with target" |
| 178 | + + " configuration. Variables can be either specified by name, in which case the" |
| 179 | + + " value will be taken from the invocation environment, or by the name=value pair" |
| 180 | + + " which sets the value independent of the invocation environment. This option can" |
| 181 | + + " be used multiple times; for options given for the same variable, the latest" |
| 182 | + + " wins, options for different variables accumulate.") |
| 183 | + public List<Map.Entry<String, String>> runEnvironment; |
167 | 184 | }
|
168 | 185 |
|
169 | 186 | private static final String NO_TARGET_MESSAGE = "No targets found to run";
|
@@ -267,6 +284,11 @@ public BlazeCommandResult exec(CommandEnvironment env, OptionsParsingResult opti
|
267 | 284 | // Only necessary in --batch since the command runs as a subprocess of the java server.
|
268 | 285 | finalRunEnv.putAll(env.getClientEnv());
|
269 | 286 | }
|
| 287 | + |
| 288 | + for (Map.Entry<String, String> entry : runOptions.runEnvironment) { |
| 289 | + finalRunEnv.put(entry.getKey(), entry.getValue()); |
| 290 | + } |
| 291 | + |
270 | 292 | ExecRequest.Builder execRequest;
|
271 | 293 | try {
|
272 | 294 | boolean shouldRunTarget = runOptions.scriptPath == null && runOptions.runBuiltTarget;
|
|
0 commit comments