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;
}
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);
}
}
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();
}
}
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();
}
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);
}
Aggregations