Search in sources :

Example 1 with ActionInput

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

the class CppLinkAction method execute.

@Override
@ThreadCompatible
public void execute(ActionExecutionContext actionExecutionContext) throws ActionExecutionException, InterruptedException {
    if (fake) {
        executeFake();
    } else {
        Executor executor = actionExecutionContext.getExecutor();
        try {
            // Collect input files
            List<ActionInput> allInputs = new ArrayList<>();
            Artifact.addExpandedArtifacts(getMandatoryInputs(), allInputs, actionExecutionContext.getArtifactExpander());
            ImmutableMap<String, String> executionInfo = ImmutableMap.of();
            if (needsToRunOnMac()) {
                executionInfo = ImmutableMap.of(ExecutionRequirements.REQUIRES_DARWIN, "");
            }
            Spawn spawn = new SimpleSpawn(this, ImmutableList.copyOf(getCommandLine()), getEnvironment(), executionInfo, ImmutableList.copyOf(allInputs), getOutputs().asList(), estimateResourceConsumptionLocal());
            executor.getSpawnActionContext(getMnemonic()).exec(spawn, actionExecutionContext);
        } catch (ExecException e) {
            throw e.toActionExecutionException("Linking of rule '" + getOwner().getLabel() + "'", executor.getVerboseFailures(), this);
        }
    }
}
Also used : Executor(com.google.devtools.build.lib.actions.Executor) ActionInput(com.google.devtools.build.lib.actions.ActionInput) SimpleSpawn(com.google.devtools.build.lib.actions.SimpleSpawn) ExecException(com.google.devtools.build.lib.actions.ExecException) ArrayList(java.util.ArrayList) SimpleSpawn(com.google.devtools.build.lib.actions.SimpleSpawn) Spawn(com.google.devtools.build.lib.actions.Spawn) ThreadCompatible(com.google.devtools.build.lib.concurrent.ThreadSafety.ThreadCompatible)

Example 2 with ActionInput

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

the class SandboxStrategy method getMounts.

public Map<PathFragment, Path> getMounts(Spawn spawn, ActionExecutionContext executionContext) throws ExecException {
    try {
        Map<PathFragment, ActionInput> inputMap = spawnInputExpander.getInputMapping(spawn, executionContext.getArtifactExpander(), executionContext.getActionInputFileCache(), executionContext.getExecutor().getContext(FilesetActionContext.class));
        Map<PathFragment, Path> mounts = new TreeMap<>();
        for (Map.Entry<PathFragment, ActionInput> e : inputMap.entrySet()) {
            mounts.put(e.getKey(), execRoot.getRelative(e.getValue().getExecPath()));
        }
        // inputs.
        for (ActionInput input : spawn.getInputFiles()) {
            if (input instanceof Artifact && ((Artifact) input).isTreeArtifact()) {
                List<Artifact> containedArtifacts = new ArrayList<>();
                executionContext.getArtifactExpander().expand((Artifact) input, containedArtifacts);
                // only mount empty TreeArtifacts as directories.
                if (containedArtifacts.isEmpty()) {
                    inputMap.put(input.getExecPath(), input);
                }
            }
        }
        return mounts;
    } catch (IOException e) {
        throw new EnvironmentalExecException("Could not prepare mounts for sandbox execution", e);
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ActionInput(com.google.devtools.build.lib.actions.ActionInput) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) ArrayList(java.util.ArrayList) IOException(java.io.IOException) EnvironmentalExecException(com.google.devtools.build.lib.actions.EnvironmentalExecException) TreeMap(java.util.TreeMap) FilesetActionContext(com.google.devtools.build.lib.rules.fileset.FilesetActionContext) Artifact(com.google.devtools.build.lib.actions.Artifact) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 3 with ActionInput

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

the class GrpcActionCache method uploadTree.

/**
   * Upload enough of the tree metadata and data into remote cache so that the entire tree can be
   * reassembled remotely using the root digest.
   */
@Override
public void uploadTree(TreeNodeRepository repository, Path execRoot, TreeNode root) throws IOException, InterruptedException {
    repository.computeMerkleDigests(root);
    // TODO(olaola): avoid querying all the digests, only ask for novel subtrees.
    ImmutableSet<ContentDigest> missingDigests = getMissingDigests(repository.getAllDigests(root));
    // Only upload data that was missing from the cache.
    ArrayList<ActionInput> actionInputs = new ArrayList<>();
    ArrayList<FileNode> treeNodes = new ArrayList<>();
    repository.getDataFromDigests(missingDigests, actionInputs, treeNodes);
    if (!treeNodes.isEmpty()) {
        CasUploadTreeMetadataRequest.Builder metaRequest = CasUploadTreeMetadataRequest.newBuilder().addAllTreeNode(treeNodes);
        CasUploadTreeMetadataReply reply = getBlockingStub().uploadTreeMetadata(metaRequest.build());
        if (!reply.getStatus().getSucceeded()) {
            throw new RuntimeException(reply.getStatus().getErrorDetail());
        }
    }
    if (!actionInputs.isEmpty()) {
        ArrayList<Path> paths = new ArrayList<>();
        for (ActionInput actionInput : actionInputs) {
            paths.add(execRoot.getRelative(actionInput.getExecPathString()));
        }
        uploadChunks(paths.size(), new BlobChunkFileIterator(missingDigests, paths.iterator()));
    }
}
Also used : Path(com.google.devtools.build.lib.vfs.Path) ActionInput(com.google.devtools.build.lib.actions.ActionInput) ArrayList(java.util.ArrayList) CasUploadTreeMetadataReply(com.google.devtools.build.lib.remote.RemoteProtocol.CasUploadTreeMetadataReply) ContentDigest(com.google.devtools.build.lib.remote.RemoteProtocol.ContentDigest) CasUploadTreeMetadataRequest(com.google.devtools.build.lib.remote.RemoteProtocol.CasUploadTreeMetadataRequest) StatusRuntimeException(io.grpc.StatusRuntimeException) FileNode(com.google.devtools.build.lib.remote.RemoteProtocol.FileNode)

Example 4 with ActionInput

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

the class RemoteSpawnStrategy method buildAction.

private Action buildAction(Collection<? extends ActionInput> outputs, ContentDigest command, ContentDigest inputRoot) {
    Action.Builder action = Action.newBuilder();
    action.setCommandDigest(command);
    action.setInputRootDigest(inputRoot);
    // Somewhat ugly: we rely on the stable order of outputs here for remote action caching.
    for (ActionInput output : outputs) {
        action.addOutputPath(output.getExecPathString());
    }
    if (platform != null) {
        action.setPlatform(platform);
    }
    return action.build();
}
Also used : Action(com.google.devtools.build.lib.remote.RemoteProtocol.Action) ActionInput(com.google.devtools.build.lib.actions.ActionInput)

Example 5 with ActionInput

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

the class TreeNodeRepository method buildFromActionInputs.

/**
   * This function is a temporary and highly inefficient hack! It builds the tree from a ready list
   * of input files. TODO(olaola): switch to creating and maintaining the TreeNodeRepository based
   * on the build graph structure.
   */
public TreeNode buildFromActionInputs(Iterable<ActionInput> actionInputs) {
    TreeMap<PathFragment, ActionInput> sortedMap = new TreeMap<>();
    for (ActionInput input : actionInputs) {
        sortedMap.put(new PathFragment(input.getExecPathString()), input);
    }
    ImmutableList.Builder<ImmutableList<String>> segments = ImmutableList.builder();
    for (PathFragment path : sortedMap.keySet()) {
        segments.add(path.getSegments());
    }
    ImmutableList<ActionInput> inputs = ImmutableList.copyOf(sortedMap.values());
    return buildParentNode(inputs, segments.build(), 0, inputs.size(), 0);
}
Also used : ActionInput(com.google.devtools.build.lib.actions.ActionInput) ImmutableList(com.google.common.collect.ImmutableList) PathFragment(com.google.devtools.build.lib.vfs.PathFragment) TreeMap(java.util.TreeMap)

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