use of com.facebook.buck.graph.MutableDirectedGraph 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();
}
use of com.facebook.buck.graph.MutableDirectedGraph in project buck by facebook.
the class NativeLinkables method getTransitiveNativeLinkables.
public static ImmutableMap<BuildTarget, NativeLinkable> getTransitiveNativeLinkables(final CxxPlatform cxxPlatform, Iterable<? extends NativeLinkable> inputs) {
final Map<BuildTarget, NativeLinkable> nativeLinkables = Maps.newHashMap();
for (NativeLinkable nativeLinkable : inputs) {
nativeLinkables.put(nativeLinkable.getBuildTarget(), nativeLinkable);
}
final MutableDirectedGraph<BuildTarget> graph = new MutableDirectedGraph<>();
AbstractBreadthFirstTraversal<BuildTarget> visitor = new AbstractBreadthFirstTraversal<BuildTarget>(nativeLinkables.keySet()) {
@Override
public ImmutableSet<BuildTarget> visit(BuildTarget target) {
NativeLinkable nativeLinkable = Preconditions.checkNotNull(nativeLinkables.get(target));
graph.addNode(target);
ImmutableSet.Builder<BuildTarget> deps = ImmutableSet.builder();
for (NativeLinkable dep : Iterables.concat(nativeLinkable.getNativeLinkableDepsForPlatform(cxxPlatform), nativeLinkable.getNativeLinkableExportedDepsForPlatform(cxxPlatform))) {
BuildTarget depTarget = dep.getBuildTarget();
graph.addEdge(target, depTarget);
deps.add(depTarget);
nativeLinkables.put(depTarget, dep);
}
return deps.build();
}
};
visitor.start();
return ImmutableMap.copyOf(nativeLinkables);
}
Aggregations