Search in sources :

Example 6 with ActionInput

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

the class SpawnInputExpander method getInputMapping.

/**
   * Convert the inputs of the given spawn to a map from exec-root relative paths to action inputs.
   * In some cases, this generates empty files, for which it uses {@link #EMPTY_FILE}.
   */
public SortedMap<PathFragment, ActionInput> getInputMapping(Spawn spawn, ArtifactExpander artifactExpander, ActionInputFileCache actionInputFileCache, FilesetActionContext filesetContext) throws IOException {
    TreeMap<PathFragment, ActionInput> inputMap = new TreeMap<>();
    addInputs(inputMap, spawn, artifactExpander);
    addRunfilesToInputs(inputMap, spawn.getRunfilesSupplier(), actionInputFileCache);
    for (Artifact manifest : spawn.getFilesetManifests()) {
        parseFilesetManifest(inputMap, manifest, filesetContext.getWorkspaceName());
    }
    return inputMap;
}
Also used : ActionInput(com.google.devtools.build.lib.actions.ActionInput) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) TreeMap(java.util.TreeMap) Artifact(com.google.devtools.build.lib.actions.Artifact)

Example 7 with ActionInput

use of com.google.devtools.build.lib.actions.ActionInput 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 ActionInput

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

the class PopulateTreeArtifactAction method checkOutputConflicts.

private void checkOutputConflicts(Collection<? extends ActionInput> outputs) throws ArtifactPrefixConflictException {
    ImmutableMap.Builder<Artifact, ActionAnalysisMetadata> generatingActions = ImmutableMap.<Artifact, ActionAnalysisMetadata>builder();
    for (ActionInput output : outputs) {
        generatingActions.put((Artifact) output, this);
    }
    Map<ActionAnalysisMetadata, ArtifactPrefixConflictException> artifactPrefixConflictMap = Actions.findArtifactPrefixConflicts(generatingActions.build());
    if (!artifactPrefixConflictMap.isEmpty()) {
        throw artifactPrefixConflictMap.values().iterator().next();
    }
}
Also used : ActionInput(com.google.devtools.build.lib.actions.ActionInput) ActionAnalysisMetadata(com.google.devtools.build.lib.actions.ActionAnalysisMetadata) 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) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 9 with ActionInput

use of com.google.devtools.build.lib.actions.ActionInput 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 10 with ActionInput

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

the class SingleBuildFileCacheTest method testUnreadableFileWhenFileSystemSupportsDigest.

@Test
public void testUnreadableFileWhenFileSystemSupportsDigest() throws Exception {
    byte[] expectedDigestRaw = MessageDigest.getInstance("md5").digest("randomtext".getBytes(StandardCharsets.UTF_8));
    ByteString expectedDigest = ByteString.copyFrom(expectedDigestRaw);
    md5Overrides.put("/unreadable", expectedDigestRaw);
    ActionInput input = ActionInputHelper.fromPath("/unreadable");
    Path file = fs.getPath("/unreadable");
    file.getOutputStream().close();
    file.chmod(0);
    ByteString actualDigest = ByteString.copyFrom(underTest.getDigest(input));
    assertThat(expectedDigest).isEqualTo(actualDigest);
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ActionInput(com.google.devtools.build.lib.actions.ActionInput) ByteString(com.google.protobuf.ByteString) Test(org.junit.Test)

Aggregations

ActionInput (com.google.devtools.build.lib.actions.ActionInput)19 Artifact (com.google.devtools.build.lib.actions.Artifact)7 ArrayList (java.util.ArrayList)7 IOException (java.io.IOException)6 Path (com.google.devtools.build.lib.vfs.Path)5 PathFragment (com.google.devtools.build.lib.vfs.PathFragment)5 Test (org.junit.Test)5 Executor (com.google.devtools.build.lib.actions.Executor)4 Spawn (com.google.devtools.build.lib.actions.Spawn)3 UserExecException (com.google.devtools.build.lib.actions.UserExecException)3 ByteString (com.google.protobuf.ByteString)3 StatusRuntimeException (io.grpc.StatusRuntimeException)3 TreeMap (java.util.TreeMap)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 TreeFileArtifact (com.google.devtools.build.lib.actions.Artifact.TreeFileArtifact)2 ArtifactPrefixConflictException (com.google.devtools.build.lib.actions.ArtifactPrefixConflictException)2 BaseSpawn (com.google.devtools.build.lib.actions.BaseSpawn)2 ExecException (com.google.devtools.build.lib.actions.ExecException)2 EventHandler (com.google.devtools.build.lib.events.EventHandler)2 Action (com.google.devtools.build.lib.remote.RemoteProtocol.Action)2