Search in sources :

Example 6 with Spawn

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();
}
Also used : BaseSpawn(com.google.devtools.build.lib.actions.BaseSpawn) Spawn(com.google.devtools.build.lib.actions.Spawn) Test(org.junit.Test)

Example 7 with Spawn

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);
    }
}
Also used : Executor(com.google.devtools.build.lib.actions.Executor) ActionInput(com.google.devtools.build.lib.actions.ActionInput) ExecException(com.google.devtools.build.lib.actions.ExecException) IOException(java.io.IOException) ActionExecutionException(com.google.devtools.build.lib.actions.ActionExecutionException) BaseSpawn(com.google.devtools.build.lib.actions.BaseSpawn) Spawn(com.google.devtools.build.lib.actions.Spawn) ArtifactPrefixConflictException(com.google.devtools.build.lib.actions.ArtifactPrefixConflictException) Artifact(com.google.devtools.build.lib.actions.Artifact) TreeFileArtifact(com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)

Example 8 with Spawn

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();
}
Also used : ActionInput(com.google.devtools.build.lib.actions.ActionInput) SpawnInfo(com.google.devtools.build.lib.actions.extra.SpawnInfo) BaseSpawn(com.google.devtools.build.lib.actions.BaseSpawn) Spawn(com.google.devtools.build.lib.actions.Spawn) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) LinkedHashMap(java.util.LinkedHashMap) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 9 with Spawn

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());
}
Also used : BaseSpawn(com.google.devtools.build.lib.actions.BaseSpawn) Spawn(com.google.devtools.build.lib.actions.Spawn) Test(org.junit.Test)

Example 10 with Spawn

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");
    }
}
Also used : ExecException(com.google.devtools.build.lib.actions.ExecException) ActionsTestUtil(com.google.devtools.build.lib.actions.util.ActionsTestUtil) BaseSpawn(com.google.devtools.build.lib.actions.BaseSpawn) Spawn(com.google.devtools.build.lib.actions.Spawn) Test(org.junit.Test)

Aggregations

Spawn (com.google.devtools.build.lib.actions.Spawn)13 BaseSpawn (com.google.devtools.build.lib.actions.BaseSpawn)10 Test (org.junit.Test)8 Artifact (com.google.devtools.build.lib.actions.Artifact)5 ActionInput (com.google.devtools.build.lib.actions.ActionInput)3 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)3 ExecException (com.google.devtools.build.lib.actions.ExecException)3 Executor (com.google.devtools.build.lib.actions.Executor)3 SimpleSpawn (com.google.devtools.build.lib.actions.SimpleSpawn)3 SpecialArtifact (com.google.devtools.build.lib.actions.Artifact.SpecialArtifact)2 ActionsTestUtil (com.google.devtools.build.lib.actions.util.ActionsTestUtil)2 IOException (java.io.IOException)2 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ActionExecutionException (com.google.devtools.build.lib.actions.ActionExecutionException)1 ArtifactPrefixConflictException (com.google.devtools.build.lib.actions.ArtifactPrefixConflictException)1 EnvironmentalExecException (com.google.devtools.build.lib.actions.EnvironmentalExecException)1 UserExecException (com.google.devtools.build.lib.actions.UserExecException)1 SpawnInfo (com.google.devtools.build.lib.actions.extra.SpawnInfo)1 RunfilesSupplierImpl (com.google.devtools.build.lib.analysis.RunfilesSupplierImpl)1