use of com.google.devtools.build.lib.actions.Spawn in project bazel by bazelbuild.
the class StandaloneSpawnStrategyTest method testStandardError.
@Test
public void testStandardError() throws Exception {
Spawn spawn = createSpawn("/bin/sh", "-c", "echo Oops! >&2");
run(spawn);
assertEquals("Oops!\n", err());
assertThat(out()).isEmpty();
}
use of com.google.devtools.build.lib.actions.Spawn in project bazel by bazelbuild.
the class PopulateTreeArtifactAction method execute.
@Override
public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException {
Executor executor = actionExecutionContext.getExecutor();
Spawn spawn;
// Create a spawn to unzip the archive file into the output TreeArtifact.
try {
spawn = createSpawn();
} catch (IOException e) {
throw new ActionExecutionException(e, this, false);
} catch (IllegalManifestFileException e) {
throw new ActionExecutionException(e, this, true);
}
// case we just return without generating anything under the output TreeArtifact.
if (spawn.getOutputFiles().isEmpty()) {
return;
}
// Check spawn output TreeFileArtifact conflicts.
try {
checkOutputConflicts(spawn.getOutputFiles());
} catch (ArtifactPrefixConflictException e) {
throw new ActionExecutionException(e, this, true);
}
// Create parent directories for the output TreeFileArtifacts.
try {
for (ActionInput fileEntry : spawn.getOutputFiles()) {
FileSystemUtils.createDirectoryAndParents(((Artifact) fileEntry).getPath().getParentDirectory());
}
} catch (IOException e) {
throw new ActionExecutionException(e, this, false);
}
// Execute the spawn.
try {
getContext(executor).exec(spawn, actionExecutionContext);
} catch (ExecException e) {
throw e.toActionExecutionException(getMnemonic() + " action failed for target: " + getOwner().getLabel(), executor.getVerboseFailures(), this);
}
// Populate the output TreeArtifact with the Spawn output TreeFileArtifacts.
for (ActionInput fileEntry : spawn.getOutputFiles()) {
actionExecutionContext.getMetadataHandler().addExpandedTreeOutput((TreeFileArtifact) fileEntry);
}
}
use of com.google.devtools.build.lib.actions.Spawn in project bazel by bazelbuild.
the class SpawnAction method getExtraActionSpawnInfo.
/**
* Returns information about this spawn action for use by the extra action mechanism.
*
* <p>Subclasses of SpawnAction may override this in order to provide action-specific behaviour.
* This can be necessary, for example, when the action discovers inputs.
*/
protected SpawnInfo getExtraActionSpawnInfo() {
SpawnInfo.Builder info = SpawnInfo.newBuilder();
Spawn spawn = getSpawn();
info.addAllArgument(spawn.getArguments());
for (Map.Entry<String, String> variable : spawn.getEnvironment().entrySet()) {
info.addVariable(EnvironmentVariable.newBuilder().setName(variable.getKey()).setValue(variable.getValue()).build());
}
for (ActionInput input : spawn.getInputFiles()) {
// Explicitly ignore middleman artifacts here.
if (!(input instanceof Artifact) || !((Artifact) input).isMiddlemanArtifact()) {
info.addInputFile(input.getExecPathString());
}
}
info.addAllOutputFile(ActionInputHelper.toExecPaths(spawn.getOutputFiles()));
return info.build();
}
use of com.google.devtools.build.lib.actions.Spawn in project bazel by bazelbuild.
the class StandaloneSpawnStrategyTest method testCommandRunsInWorkingDir.
@Test
public void testCommandRunsInWorkingDir() throws Exception {
Spawn spawn = createSpawn("/bin/pwd");
run(spawn);
assertEquals(executor.getExecRoot() + "\n", out());
}
use of com.google.devtools.build.lib.actions.Spawn in project bazel by bazelbuild.
the class StandaloneSpawnStrategyTest method testIOSEnvironmentOnNonDarwin.
// Test an action with environment variables set indicating an action running on a darwin host
// system. Such actions should fail given the fact that these tests run on a non darwin
// architecture.
@Test
public void testIOSEnvironmentOnNonDarwin() throws Exception {
if (OS.getCurrent() == OS.DARWIN) {
return;
}
Spawn spawn = new BaseSpawn.Local(Arrays.asList("/bin/sh", "-c", "echo $SDKROOT"), ImmutableMap.<String, String>of(AppleConfiguration.APPLE_SDK_VERSION_ENV_NAME, "8.4", AppleConfiguration.APPLE_SDK_PLATFORM_ENV_NAME, "iPhoneSimulator"), new ActionsTestUtil.NullAction(), ResourceSet.ZERO);
try {
run(spawn);
fail("action should fail due to being unable to resolve SDKROOT");
} catch (ExecException e) {
assertThat(e.getMessage()).contains("Cannot locate iOS SDK on non-darwin operating system");
}
}
Aggregations