Search in sources :

Example 1 with BuildJobStateTargetNode

use of com.facebook.buck.distributed.thrift.BuildJobStateTargetNode in project buck by facebook.

the class DistBuildServiceTest method canUploadTargetGraph.

@Test
public void canUploadTargetGraph() throws IOException, ExecutionException, InterruptedException {
    Capture<FrontendRequest> request = EasyMock.newCapture();
    FrontendResponse response = new FrontendResponse();
    response.setType(FrontendRequestType.STORE_BUILD_GRAPH);
    response.setWasSuccessful(true);
    EasyMock.expect(frontendService.makeRequest(EasyMock.capture(request))).andReturn(response).once();
    EasyMock.replay(frontendService);
    BuildJobState buildJobState = new BuildJobState();
    List<BuildJobStateFileHashes> fileHashes = new ArrayList<>();
    buildJobState.setFileHashes(fileHashes);
    BuildJobStateTargetGraph graph = new BuildJobStateTargetGraph();
    graph.setNodes(new ArrayList<BuildJobStateTargetNode>());
    BuildJobStateTargetNode node1 = new BuildJobStateTargetNode();
    node1.setRawNode("node1");
    BuildJobStateTargetNode node2 = new BuildJobStateTargetNode();
    node2.setRawNode("node1");
    graph.addToNodes(node1);
    graph.addToNodes(node2);
    buildJobState.setTargetGraph(graph);
    StampedeId stampedeId = new StampedeId();
    stampedeId.setId("check-id");
    distBuildService.uploadTargetGraph(buildJobState, stampedeId, executor).get();
    Assert.assertTrue(request.getValue().isSetType());
    Assert.assertEquals(request.getValue().getType(), FrontendRequestType.STORE_BUILD_GRAPH);
    Assert.assertTrue(request.getValue().isSetStoreBuildGraphRequest());
    Assert.assertTrue(request.getValue().getStoreBuildGraphRequest().isSetStampedeId());
    Assert.assertEquals(request.getValue().getStoreBuildGraphRequest().getStampedeId(), stampedeId);
    Assert.assertTrue(request.getValue().getStoreBuildGraphRequest().isSetBuildGraph());
    BuildJobState sentState = BuildJobStateSerializer.deserialize(request.getValue().getStoreBuildGraphRequest().getBuildGraph());
    Assert.assertTrue(buildJobState.equals(sentState));
}
Also used : BuildJobStateTargetNode(com.facebook.buck.distributed.thrift.BuildJobStateTargetNode) BuildJobStateFileHashes(com.facebook.buck.distributed.thrift.BuildJobStateFileHashes) BuildJobStateTargetGraph(com.facebook.buck.distributed.thrift.BuildJobStateTargetGraph) StampedeId(com.facebook.buck.distributed.thrift.StampedeId) FrontendResponse(com.facebook.buck.distributed.thrift.FrontendResponse) BuildJobState(com.facebook.buck.distributed.thrift.BuildJobState) ArrayList(java.util.ArrayList) FrontendRequest(com.facebook.buck.distributed.thrift.FrontendRequest) Test(org.junit.Test)

Example 2 with BuildJobStateTargetNode

use of com.facebook.buck.distributed.thrift.BuildJobStateTargetNode in project buck by facebook.

the class DistBuildTargetGraphCodec method dump.

public BuildJobStateTargetGraph dump(Collection<TargetNode<?, ?>> targetNodes, Function<Path, Integer> cellIndexer) {
    BuildJobStateTargetGraph result = new BuildJobStateTargetGraph();
    for (TargetNode<?, ?> targetNode : targetNodes) {
        Map<String, Object> rawTargetNode = nodeToRawNode.apply(targetNode);
        ProjectFilesystem projectFilesystem = targetNode.getFilesystem();
        BuildJobStateTargetNode remoteNode = new BuildJobStateTargetNode();
        remoteNode.setCellIndex(cellIndexer.apply(projectFilesystem.getRootPath()));
        remoteNode.setBuildTarget(encodeBuildTarget(targetNode.getBuildTarget()));
        try {
            remoteNode.setRawNode(objectMapper.writeValueAsString(rawTargetNode));
        } catch (JsonProcessingException e) {
            throw new RuntimeException(e);
        }
        result.addToNodes(remoteNode);
    }
    return result;
}
Also used : BuildJobStateTargetNode(com.facebook.buck.distributed.thrift.BuildJobStateTargetNode) BuildJobStateTargetGraph(com.facebook.buck.distributed.thrift.BuildJobStateTargetGraph) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) JsonProcessingException(com.fasterxml.jackson.core.JsonProcessingException)

Example 3 with BuildJobStateTargetNode

use of com.facebook.buck.distributed.thrift.BuildJobStateTargetNode in project buck by facebook.

the class DistBuildTargetGraphCodec method createTargetGraph.

public TargetGraphAndBuildTargets createTargetGraph(BuildJobStateTargetGraph remoteTargetGraph, Function<Integer, Cell> cellLookup) throws IOException {
    ImmutableMap.Builder<BuildTarget, TargetNode<?, ?>> targetNodeIndexBuilder = ImmutableMap.builder();
    ImmutableSet.Builder<BuildTarget> buildTargetsBuilder = ImmutableSet.builder();
    for (BuildJobStateTargetNode remoteNode : remoteTargetGraph.getNodes()) {
        Cell cell = cellLookup.apply(remoteNode.getCellIndex());
        ProjectFilesystem projectFilesystem = cell.getFilesystem();
        BuildTarget target = decodeBuildTarget(remoteNode.getBuildTarget(), cell);
        if (topLevelTargets.contains(target.getFullyQualifiedName())) {
            buildTargetsBuilder.add(target);
        }
        @SuppressWarnings("unchecked") Map<String, Object> rawNode = objectMapper.readValue(remoteNode.getRawNode(), Map.class);
        Path buildFilePath = projectFilesystem.resolve(target.getBasePath()).resolve(cell.getBuildFileName());
        TargetNode<?, ?> targetNode = parserTargetNodeFactory.createTargetNode(cell, buildFilePath, target, rawNode, input -> SimplePerfEvent.scope(Optional.empty(), input));
        targetNodeIndexBuilder.put(targetNode.getBuildTarget(), targetNode);
    }
    ImmutableSet<BuildTarget> buildTargets = buildTargetsBuilder.build();
    Preconditions.checkArgument(topLevelTargets.size() == buildTargets.size());
    ImmutableMap<BuildTarget, TargetNode<?, ?>> targetNodeIndex = targetNodeIndexBuilder.build();
    MutableDirectedGraph<TargetNode<?, ?>> mutableTargetGraph = new MutableDirectedGraph<>();
    for (TargetNode<?, ?> targetNode : targetNodeIndex.values()) {
        mutableTargetGraph.addNode(targetNode);
        for (BuildTarget dep : targetNode.getDeps()) {
            mutableTargetGraph.addEdge(targetNode, Preconditions.checkNotNull(targetNodeIndex.get(dep)));
        }
    }
    // TODO(tophyr): make this work with TargetGroups
    TargetGraph targetGraph = new TargetGraph(mutableTargetGraph, targetNodeIndex, ImmutableSet.of());
    return TargetGraphAndBuildTargets.builder().setTargetGraph(targetGraph).addAllBuildTargets(buildTargets).build();
}
Also used : Path(java.nio.file.Path) BuildJobStateTargetNode(com.facebook.buck.distributed.thrift.BuildJobStateTargetNode) BuildJobStateTargetNode(com.facebook.buck.distributed.thrift.BuildJobStateTargetNode) TargetNode(com.facebook.buck.rules.TargetNode) BuildJobStateTargetGraph(com.facebook.buck.distributed.thrift.BuildJobStateTargetGraph) TargetGraph(com.facebook.buck.rules.TargetGraph) ImmutableMap(com.google.common.collect.ImmutableMap) ImmutableSet(com.google.common.collect.ImmutableSet) UnflavoredBuildTarget(com.facebook.buck.model.UnflavoredBuildTarget) BuildJobStateBuildTarget(com.facebook.buck.distributed.thrift.BuildJobStateBuildTarget) BuildTarget(com.facebook.buck.model.BuildTarget) ProjectFilesystem(com.facebook.buck.io.ProjectFilesystem) Cell(com.facebook.buck.rules.Cell) MutableDirectedGraph(com.facebook.buck.graph.MutableDirectedGraph)

Aggregations

BuildJobStateTargetGraph (com.facebook.buck.distributed.thrift.BuildJobStateTargetGraph)3 BuildJobStateTargetNode (com.facebook.buck.distributed.thrift.BuildJobStateTargetNode)3 ProjectFilesystem (com.facebook.buck.io.ProjectFilesystem)2 BuildJobState (com.facebook.buck.distributed.thrift.BuildJobState)1 BuildJobStateBuildTarget (com.facebook.buck.distributed.thrift.BuildJobStateBuildTarget)1 BuildJobStateFileHashes (com.facebook.buck.distributed.thrift.BuildJobStateFileHashes)1 FrontendRequest (com.facebook.buck.distributed.thrift.FrontendRequest)1 FrontendResponse (com.facebook.buck.distributed.thrift.FrontendResponse)1 StampedeId (com.facebook.buck.distributed.thrift.StampedeId)1 MutableDirectedGraph (com.facebook.buck.graph.MutableDirectedGraph)1 BuildTarget (com.facebook.buck.model.BuildTarget)1 UnflavoredBuildTarget (com.facebook.buck.model.UnflavoredBuildTarget)1 Cell (com.facebook.buck.rules.Cell)1 TargetGraph (com.facebook.buck.rules.TargetGraph)1 TargetNode (com.facebook.buck.rules.TargetNode)1 JsonProcessingException (com.fasterxml.jackson.core.JsonProcessingException)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Path (java.nio.file.Path)1 ArrayList (java.util.ArrayList)1