Search in sources :

Example 1 with SpawnInfo

use of com.google.devtools.build.lib.actions.extra.SpawnInfo 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 2 with SpawnInfo

use of com.google.devtools.build.lib.actions.extra.SpawnInfo in project bazel by bazelbuild.

the class SpawnActionTest method testExtraActionInfoEnvironmentVariables.

/**
   * Test that environment variables are not escaped or quoted.
   */
@Test
public void testExtraActionInfoEnvironmentVariables() throws Exception {
    Map<String, String> env = ImmutableMap.of("P1", "simple", "P2", "spaces are not escaped", "P3", ":", "P4", "", "NONSENSE VARIABLE", "value");
    SpawnInfo spawnInfo = createCopyFromWelcomeToDestination(env).getExtraActionInfo().build().getExtension(SpawnInfo.spawnInfo);
    assertThat(env).hasSize(spawnInfo.getVariableCount());
    for (EnvironmentVariable variable : spawnInfo.getVariableList()) {
        assertThat(env).containsEntry(variable.getName(), variable.getValue());
    }
}
Also used : SpawnInfo(com.google.devtools.build.lib.actions.extra.SpawnInfo) EnvironmentVariable(com.google.devtools.build.lib.actions.extra.EnvironmentVariable) Test(org.junit.Test)

Example 3 with SpawnInfo

use of com.google.devtools.build.lib.actions.extra.SpawnInfo in project bazel by bazelbuild.

the class SpawnActionTest method testExtraActionInfo.

@Test
public void testExtraActionInfo() throws Exception {
    SpawnAction action = createCopyFromWelcomeToDestination(ImmutableMap.<String, String>of());
    ExtraActionInfo info = action.getExtraActionInfo().build();
    assertEquals("Dummy", info.getMnemonic());
    SpawnInfo spawnInfo = info.getExtension(SpawnInfo.spawnInfo);
    assertNotNull(spawnInfo);
    assertThat(spawnInfo.getArgumentList()).containsExactlyElementsIn(action.getArguments());
    Iterable<String> inputPaths = Artifact.toExecPaths(action.getInputs());
    Iterable<String> outputPaths = Artifact.toExecPaths(action.getOutputs());
    assertThat(spawnInfo.getInputFileList()).containsExactlyElementsIn(inputPaths);
    assertThat(spawnInfo.getOutputFileList()).containsExactlyElementsIn(outputPaths);
    Map<String, String> environment = action.getEnvironment();
    assertEquals(environment.size(), spawnInfo.getVariableCount());
    for (EnvironmentVariable variable : spawnInfo.getVariableList()) {
        assertThat(environment).containsEntry(variable.getName(), variable.getValue());
    }
}
Also used : SpawnInfo(com.google.devtools.build.lib.actions.extra.SpawnInfo) EnvironmentVariable(com.google.devtools.build.lib.actions.extra.EnvironmentVariable) ExtraActionInfo(com.google.devtools.build.lib.actions.extra.ExtraActionInfo) Test(org.junit.Test)

Example 4 with SpawnInfo

use of com.google.devtools.build.lib.actions.extra.SpawnInfo in project heron by twitter.

the class PythonCheckstyle method getSourceFiles.

@SuppressWarnings("unchecked")
private static Collection<String> getSourceFiles(String extraActionFile) {
    ExtraActionInfo info = ExtraActionUtils.getExtraActionInfo(extraActionFile);
    SpawnInfo spawnInfo = info.getExtension(SpawnInfo.spawnInfo);
    return Collections2.filter(spawnInfo.getInputFileList(), Predicates.and(Predicates.containsPattern(".*/src/.+\\.py[c]{0,1}$"), Predicates.not(Predicates.containsPattern("third_party/"))));
}
Also used : SpawnInfo(com.google.devtools.build.lib.actions.extra.SpawnInfo) ExtraActionInfo(com.google.devtools.build.lib.actions.extra.ExtraActionInfo)

Aggregations

SpawnInfo (com.google.devtools.build.lib.actions.extra.SpawnInfo)4 EnvironmentVariable (com.google.devtools.build.lib.actions.extra.EnvironmentVariable)2 ExtraActionInfo (com.google.devtools.build.lib.actions.extra.ExtraActionInfo)2 Test (org.junit.Test)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 ActionInput (com.google.devtools.build.lib.actions.ActionInput)1 Artifact (com.google.devtools.build.lib.actions.Artifact)1 BaseSpawn (com.google.devtools.build.lib.actions.BaseSpawn)1 Spawn (com.google.devtools.build.lib.actions.Spawn)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1