diff --git a/examples/bazel-example/.gitignore b/examples/bazel-example/.gitignore new file mode 100644 index 00000000..ac41fd29 --- /dev/null +++ b/examples/bazel-example/.gitignore @@ -0,0 +1 @@ +bazel-bazel-example diff --git a/lsif-semanticdb/src/main/java/com/sourcegraph/lsif_semanticdb/BazelBuildTool.java b/lsif-semanticdb/src/main/java/com/sourcegraph/lsif_semanticdb/BazelBuildTool.java index a545013c..25891ee6 100644 --- a/lsif-semanticdb/src/main/java/com/sourcegraph/lsif_semanticdb/BazelBuildTool.java +++ b/lsif-semanticdb/src/main/java/com/sourcegraph/lsif_semanticdb/BazelBuildTool.java @@ -15,7 +15,7 @@ public class BazelBuildTool { - public static int runAndReturnExitCode(String[] args) throws IOException { + public static int runAndReturnExitCode(String[] args) throws IOException, InterruptedException { Optional maybeOptions = BazelOptions.parse(args); if (!maybeOptions.isPresent()) { return 1; @@ -56,7 +56,8 @@ public void error(Throwable e) { return 0; } - public static List mavenPackages(BazelOptions options) throws IOException { + public static List mavenPackages(BazelOptions options) + throws IOException, InterruptedException { ArrayList result = new ArrayList<>(); if (!options.isQueryMavenImports) { return result; @@ -109,22 +110,19 @@ public static List mavenPackages(BazelOptions options) throws IOEx } public static Bazelbuild.QueryResult runBazelQuery(BazelOptions options, String query) - throws IOException { + throws IOException, InterruptedException { List command = Arrays.asList(options.bazelBinary, "query", query, "--output=proto"); System.out.println("running: " + String.join(" ", command)); Process bazelQuery = new ProcessBuilder(command).directory(options.sourceroot.toFile()).start(); byte[] bytes = InputStreamBytes.readAll(bazelQuery.getInputStream()); - if (bazelQuery.isAlive()) { - throw new RuntimeException(new String(InputStreamBytes.readAll(bazelQuery.getErrorStream()))); - } - int exitValue = bazelQuery.exitValue(); + int exitValue = bazelQuery.waitFor(); if (exitValue != 0) { throw new RuntimeException("bazel command failed\n" + new String(bytes)); } return Bazelbuild.QueryResult.parseFrom(bytes); } - public static void main(String[] args) throws IOException { + public static void main(String[] args) throws IOException, InterruptedException { System.exit(runAndReturnExitCode(args)); } }