Skip to content

Commit de33fde

Browse files
committed
Propagate test envs to xml generation action
Previously, we hardcode the envs of the xml generation action, which caused problem for process-wrapper because it's dynamically linked to some system library and the required PATH or LD_LIBRARY_PATH are not set. This change propagate the envs we set for the actual test action to the xml file generation action to make sure the env vars are correctly set and can also be controlled by --action_env and --test_env. Fixes #4137
1 parent 52457b1 commit de33fde

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/main/java/com/google/devtools/build/lib/exec/StandaloneTestStrategy.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -391,26 +391,23 @@ private static BuildEventStreamProtos.TestResult.ExecutionInfo extractExecutionI
391391
* A spawn to generate a test.xml file from the test log. This is only used if the test does not
392392
* generate a test.xml file itself.
393393
*/
394-
private static Spawn createXmlGeneratingSpawn(TestRunnerAction action, SpawnResult result) {
394+
private static Spawn createXmlGeneratingSpawn(TestRunnerAction action, ImmutableMap<String, String> testEnv, SpawnResult result) {
395395
ImmutableList<String> args =
396396
ImmutableList.of(
397397
action.getTestXmlGeneratorScript().getExecPath().getCallablePathString(),
398398
action.getTestLog().getExecPathString(),
399399
action.getXmlOutputPath().getPathString(),
400400
Long.toString(result.getWallTime().orElse(Duration.ZERO).getSeconds()),
401401
Integer.toString(result.exitCode()));
402-
403-
String testBinaryName =
404-
action.getExecutionSettings().getExecutable().getRootRelativePath().getCallablePathString();
402+
ImmutableMap.Builder<String, String> envBuilder = ImmutableMap.builder();
403+
envBuilder.putAll(testEnv)
404+
.put("TEST_SHARD_INDEX", Integer.toString(action.getShardNum()))
405+
.put("TEST_TOTAL_SHARDS", Integer.toString(action.getExecutionSettings().getTotalShards()))
406+
.put("TEST_NAME", action.getTestName());
405407
return new SimpleSpawn(
406408
action,
407409
args,
408-
ImmutableMap.of(
409-
"PATH", "/usr/bin:/bin",
410-
"TEST_SHARD_INDEX", Integer.toString(action.getShardNum()),
411-
"TEST_TOTAL_SHARDS", Integer.toString(action.getExecutionSettings().getTotalShards()),
412-
"TEST_NAME", action.getTestName(),
413-
"TEST_BINARY", testBinaryName),
410+
envBuilder.build(),
414411
// Pass the execution info of the action which is identical to the supported tags set on the
415412
// test target. In particular, this does not set the test timeout on the spawn.
416413
ImmutableMap.copyOf(action.getExecutionInfo()),
@@ -766,7 +763,8 @@ public TestAttemptContinuation execute()
766763
if (executionOptions.splitXmlGeneration
767764
&& fileOutErr.getOutputPath().exists()
768765
&& !xmlOutputPath.exists()) {
769-
Spawn xmlGeneratingSpawn = createXmlGeneratingSpawn(testAction, spawnResults.get(0));
766+
767+
Spawn xmlGeneratingSpawn = createXmlGeneratingSpawn(testAction, spawn.getEnvironment(), spawnResults.get(0));
770768
SpawnStrategyResolver spawnStrategyResolver =
771769
actionExecutionContext.getContext(SpawnStrategyResolver.class);
772770
// We treat all failures to generate the test.xml here as catastrophic, and won't rerun

0 commit comments

Comments
 (0)