diff --git a/.gitignore b/.gitignore index e702ac9b85..1b93f20aa2 100644 --- a/.gitignore +++ b/.gitignore @@ -9,6 +9,7 @@ .DS_Store .gwt_work_dir /.apt_generated +/.bazel_path /.buckd /.classpath /.factorypath diff --git a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/BazelBuild.java b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/BazelBuild.java index d2e3b58d94..5faca9c9b7 100644 --- a/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/BazelBuild.java +++ b/gerrit-httpd/src/main/java/com/google/gerrit/httpd/raw/BazelBuild.java @@ -14,6 +14,7 @@ package com.google.gerrit.httpd.raw; +import static com.google.common.base.MoreObjects.firstNonNull; import static java.nio.charset.StandardCharsets.UTF_8; import com.google.common.escape.Escaper; @@ -25,7 +26,11 @@ import java.io.IOException; import java.io.InputStream; import java.io.InterruptedIOException; import java.io.PrintWriter; +import java.nio.file.Files; +import java.nio.file.NoSuchFileException; import java.nio.file.Path; +import java.util.Properties; + import javax.servlet.http.HttpServletResponse; import org.eclipse.jgit.util.RawParseUtils; import org.slf4j.Logger; @@ -117,8 +122,24 @@ public class BazelBuild { } } - private ProcessBuilder newBuildProcess(Label label) { - return new ProcessBuilder("bazel", "build", label.fullName()); + private Properties loadBuildProperties(Path propPath) throws IOException { + Properties properties = new Properties(); + try (InputStream in = Files.newInputStream(propPath)) { + properties.load(in); + } catch (NoSuchFileException e) { + // Ignore; will be run from PATH, with a descriptive error if it fails. + } + return properties; + } + + private ProcessBuilder newBuildProcess(Label label) throws IOException { + Properties properties = loadBuildProperties(sourceRoot.resolve(".bazel_path")); + String bazel = firstNonNull(properties.getProperty("bazel"), "bazel"); + ProcessBuilder proc = new ProcessBuilder(bazel, "build", label.fullName()); + if (properties.containsKey("PATH")) { + proc.environment().put("PATH", properties.getProperty("PATH")); + } + return proc; } /** returns the root relative path to the artifact for the given label */ diff --git a/tools/eclipse/project.py b/tools/eclipse/project.py index 7ea09892ed..5e8d69af31 100755 --- a/tools/eclipse/project.py +++ b/tools/eclipse/project.py @@ -56,6 +56,12 @@ args, _ = opts.parse_args() def retrieve_ext_location(): return check_output(['bazel', 'info', 'output_base']).strip() +def gen_bazel_path(): + bazel = check_output(['which', 'bazel']).strip() + with open(path.join(ROOT, ".bazel_path"), 'w') as fd: + fd.write("bazel=%s\n" % bazel) + fd.write("PATH=%s\n" % environ["PATH"]) + def _query_classpath(target): deps = [] t = cp_targets[target] @@ -258,6 +264,7 @@ try: gen_project(args.project_name) gen_classpath(ext_location) gen_factorypath(ext_location) + gen_bazel_path() # TODO(davido): Remove this when GWT gone gwt_working_dir = ".gwt_work_dir"