Java Code Examples for com.google.devtools.build.lib.query2.proto.proto2api.Build#Target

The following examples show how to use com.google.devtools.build.lib.query2.proto.proto2api.Build#Target . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Bazel.java    From bazel-tools with Apache License 2.0 5 votes vote down vote up
public static ImmutableGraph<String> dependencyGraph(final Path workspace, final Rule rule)
    throws IOException {
  final Process process =
      new ProcessBuilder("bazel", "query", "--output=proto", "deps(" + rule + ") + " + rule)
          .redirectError(ProcessBuilder.Redirect.INHERIT)
          .redirectOutput(ProcessBuilder.Redirect.PIPE)
          .directory(workspace.toFile())
          .start();

  try {
    final Build.QueryResult queryResult = Build.QueryResult.parseFrom(process.getInputStream());

    final MutableGraph<String> graph =
        GraphBuilder.directed().expectedNodeCount(queryResult.getTargetCount()).build();

    for (final Build.Target protoTarget : queryResult.getTargetList()) {
      final String name = protoTarget.getRule().getName();
      graph.addNode(name);

      for (final String dependency : protoTarget.getRule().getRuleInputList()) {
        graph.putEdge(name, dependency);
      }
    }

    return ImmutableGraph.copyOf(graph);
  } finally {
    process.destroyForcibly();
  }
}
 
Example 2
Source File: QueryIntegrationTest.java    From bazel with Apache License 2.0 5 votes vote down vote up
private static List<String> getTargetNames(QueryResult result) {
  List<String> results = new ArrayList<>();
  for (Build.Target target : result.getTargetList()) {
    results.add(target.getRule().getName());
  }
  return results;
}
 
Example 3
Source File: ProtoOutputFormatter.java    From bazel with Apache License 2.0 4 votes vote down vote up
/** Converts a logical {@link Target} object into a {@link Build.Target} protobuffer. */
public Build.Target toTargetProtoBuffer(Target target) throws InterruptedException {
  return toTargetProtoBuffer(target, /*extraDataForAttrHash=*/ "");
}