Merge "Fix the buck springboard to always work from Eclipse"

This commit is contained in:
Dave Borowitz 2013-05-13 23:38:13 +00:00 committed by Gerrit Code Review
commit bc7a9ea30c
4 changed files with 49 additions and 17 deletions

View File

@ -17,6 +17,7 @@ package com.google.gerrit.pgm.http.jetty;
import static java.util.concurrent.TimeUnit.MILLISECONDS; import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.SECONDS; import static java.util.concurrent.TimeUnit.SECONDS;
import com.google.common.base.Objects;
import com.google.common.io.ByteStreams; import com.google.common.io.ByteStreams;
import com.google.gerrit.extensions.events.LifecycleListener; import com.google.gerrit.extensions.events.LifecycleListener;
import com.google.gerrit.launcher.GerritLauncher; import com.google.gerrit.launcher.GerritLauncher;
@ -54,6 +55,7 @@ import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException; import java.io.FileNotFoundException;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -68,6 +70,7 @@ import java.util.EnumSet;
import java.util.Enumeration; import java.util.Enumeration;
import java.util.HashSet; import java.util.HashSet;
import java.util.List; import java.util.List;
import java.util.Properties;
import java.util.Set; import java.util.Set;
import java.util.zip.ZipEntry; import java.util.zip.ZipEntry;
import java.util.zip.ZipFile; import java.util.zip.ZipFile;
@ -488,7 +491,7 @@ public class JettyServer {
String target = targetForBrowser(System.getProperty("gerrit.browser")); String target = targetForBrowser(System.getProperty("gerrit.browser"));
File gen = new File(dir, "gen"); File gen = new File(dir, "gen");
String out = new File(new File(gen, pkg), target).getAbsolutePath(); String out = new File(new File(gen, pkg), target).getAbsolutePath();
build(dir.getParentFile(), out + ".rebuild", "//" + pkg + ":" + target); build(dir.getParentFile(), gen, "//" + pkg + ":" + target);
return unpackWar(new File(out + ".zip")); return unpackWar(new File(out + ".zip"));
} else if ("target".equals(dir.getName())) { } else if ("target".equals(dir.getName())) {
return useMavenDeveloperBuild(dir); return useMavenDeveloperBuild(dir);
@ -507,15 +510,19 @@ public class JettyServer {
} }
} }
private static void build(File root, String cmd, String target) private static void build(File root, File gen, String target)
throws IOException { throws IOException {
long start = System.currentTimeMillis();
log.info("buck build " + target); log.info("buck build " + target);
Process rebuild = new ProcessBuilder(cmd, target) Properties properties = loadBuckProperties(gen);
String buck = Objects.firstNonNull(properties.getProperty("buck"), "buck");
ProcessBuilder proc = new ProcessBuilder(buck, "build", target)
.directory(root) .directory(root)
.redirectErrorStream(true) .redirectErrorStream(true);
.start(); if (properties.contains("PATH")) {
proc.environment().put("PATH", properties.getProperty("PATH"));
}
long start = System.currentTimeMillis();
Process rebuild = proc.start();
byte[] out; byte[] out;
InputStream in = rebuild.getInputStream(); InputStream in = rebuild.getInputStream();
try { try {
@ -529,7 +536,7 @@ public class JettyServer {
try { try {
status = rebuild.waitFor(); status = rebuild.waitFor();
} catch (InterruptedException e) { } catch (InterruptedException e) {
throw new InterruptedIOException("interrupted waiting for " + cmd); throw new InterruptedIOException("interrupted waiting for " + buck);
} }
if (status != 0) { if (status != 0) {
System.err.write(out); System.err.write(out);
@ -541,6 +548,19 @@ public class JettyServer {
log.info(String.format("UPDATED %s in %.3fs", target, time / 1000.0)); log.info(String.format("UPDATED %s in %.3fs", target, time / 1000.0));
} }
private static Properties loadBuckProperties(File gen)
throws FileNotFoundException, IOException {
Properties properties = new Properties();
InputStream in = new FileInputStream(
new File(new File(gen, "tools"), "buck.properties"));
try {
properties.load(in);
} finally {
in.close();
}
return properties;
}
private Resource useMavenDeveloperBuild(File dir) throws IOException { private Resource useMavenDeveloperBuild(File dir) throws IOException {
dir = dir.getParentFile(); // pop target dir = dir.getParentFile(); // pop target
dir = dir.getParentFile(); // pop the module we are in dir = dir.getParentFile(); // pop the module we are in

View File

@ -16,7 +16,7 @@
from __future__ import print_function from __future__ import print_function
from multiprocessing import cpu_count from multiprocessing import cpu_count
from os import environ, fchmod, makedirs, mkdir, path from os import environ, makedirs, mkdir, path
from subprocess import Popen, PIPE from subprocess import Popen, PIPE
from sys import argv, stderr from sys import argv, stderr
@ -60,11 +60,3 @@ out, err = gwt.communicate()
if gwt.returncode != 0: if gwt.returncode != 0:
print(out + err, file=stderr) print(out + err, file=stderr)
exit(gwt.returncode) exit(gwt.returncode)
with open(rebuild, 'w') as fd:
def shquote(s):
return s.replace("'", "'\\''")
print('#!/bin/sh', file=fd)
print("PATH='%s'" % shquote(environ['PATH']), file=fd)
print('buck build "$1" || exit', file=fd)
fchmod(fd.fileno(), 0o755)

View File

@ -9,3 +9,21 @@ python_binary(
main = 'pack_war.py', main = 'pack_war.py',
visibility = ['PUBLIC'], visibility = ['PUBLIC'],
) )
def shquote(s):
return s.replace("'", "'\\''")
def os_path():
from os import environ
return environ.get('PATH')
genrule(
name = 'buck.properties',
cmd = 'echo buck=`which buck`>$OUT;' +
("echo PATH=\''%s'\' >>$OUT;" % shquote(os_path())),
srcs = [],
deps = [],
out = 'buck.properties',
visibility = ['PUBLIC'],
)

View File

@ -7,6 +7,7 @@ genrule(
deps = [ deps = [
':_classpath', ':_classpath',
':_project', ':_project',
'//tools:buck.properties',
], ],
out = '__fake.eclipse__', out = '__fake.eclipse__',
) )
@ -18,6 +19,7 @@ genrule(
deps = [ deps = [
':_classpath_nocompile', ':_classpath_nocompile',
':_project', ':_project',
'//tools:buck.properties',
], ],
out = '__fake.eclipse__', out = '__fake.eclipse__',
) )