Update Buck
Latest version of buck is faster than the prior version used by
Gerrit. No-op updates when loading a debug version of the UI now take
only 1.804s on my laptop (previously 7s) and a draft UI compile is
only 24.659s (previously 39s).
The slow acceptance tests must now be excluded with `--exclude slow`.
Buck changed the meaning of the -e option to be --emulator, which is
unfortunately useful only for Android application developers.
genrule() now needs to use $(exe) to reference the binary to run,
offers $(location) to make it easier to find files in the build tree.
The empty srcs array is no longer required for genrule(). Buck has
determined it is sufficiently powerful with $(location) and deps that
requiring srcs is unnecessary.
Supporting .src.zip files in the srcs array of java_library() means
Gerrit no longer needs to run a separate genrule() to extract files
produced by ANTLR, or call javac inside of the BuckPrologCompiler
support glue.
Change-Id: Ib03042921a081b867a7aad0423bd45523e42917a
diff --git a/lib/codemirror/BUCK b/lib/codemirror/BUCK
index 47623b5..884d12d 100644
--- a/lib/codemirror/BUCK
+++ b/lib/codemirror/BUCK
@@ -33,11 +33,10 @@
genrule(
name = 'download',
- cmd = '${//tools:download_file}' +
+ cmd = '$(exe //tools:download_file)' +
' -o $OUT' +
' -u ' + URL +
' -v ' + SHA1,
- srcs = [],
deps = ['//tools:download_file'],
out = 'codemirror-' + VERSION + '.zip',
)
diff --git a/lib/maven.defs b/lib/maven.defs
index 551c951..ac98652 100644
--- a/lib/maven.defs
+++ b/lib/maven.defs
@@ -62,7 +62,7 @@
srcjar = jar + '-src.jar'
srcurl = url + '-sources.jar'
- cmd = ['${//tools:download_file}', '-o', '$OUT', '-u', binurl]
+ cmd = ['$(exe //tools:download_file)', '-o', '$OUT', '-u', binurl]
if sha1:
cmd.extend(['-v', sha1])
elif bin_sha1:
@@ -75,20 +75,18 @@
genrule(
name = name + '__download_bin',
cmd = ' '.join(cmd),
- srcs = [],
deps = ['//tools:download_file'],
out = binjar,
)
license = ['//lib:LICENSE-' + license]
if src_sha1 or attach_source:
- cmd = ['${//tools:download_file}', '-o', '$OUT', '-u', srcurl]
+ cmd = ['$(exe //tools:download_file)', '-o', '$OUT', '-u', srcurl]
if src_sha1:
cmd.extend(['-v', src_sha1])
genrule(
name = name + '__download_src',
cmd = ' '.join(cmd),
- srcs = [],
deps = ['//tools:download_file'],
out = srcjar,
)
@@ -104,7 +102,6 @@
genrule(
name = name + '__download_src',
cmd = ':>$OUT',
- srcs = [],
out = '__' + name + '__no_src',
)
diff --git a/lib/prolog/DEFS b/lib/prolog/DEFS
index 38d7fe5..e788106 100644
--- a/lib/prolog/DEFS
+++ b/lib/prolog/DEFS
@@ -18,21 +18,29 @@
deps = [],
visibility = []):
genrule(
- name = name + '_prolog2java',
- cmd = '${//lib/prolog:compiler} $SRCS $DEPS $OUT',
+ name = name + '__pl2j',
+ cmd = '$(exe //lib/prolog:compiler) $SRCS $DEPS $OUT',
srcs = srcs,
+ deps = ['//lib/prolog:compiler'],
+ out = name + '.src.zip',
+ )
+ java_library(
+ name = name + '__lib',
+ srcs = [genfile(name + '.src.zip')],
deps = [
- '//lib/prolog:compiler',
+ ':' + name + '__pl2j',
'//lib/prolog:prolog-cafe',
] + deps,
+ )
+ genrule(
+ name = name + '__ln',
+ cmd = 'ln -s $(location :%s__lib) $OUT' % name,
+ deps = [':%s__lib' % name],
out = name + '.jar',
)
prebuilt_jar(
name = name,
binary_jar = genfile(name + '.jar'),
- deps = [
- ':' + name + '_prolog2java',
- '//lib/prolog:prolog-cafe',
- ] + deps,
+ deps = [':%s__ln' % name],
visibility = visibility,
)
diff --git a/lib/prolog/java/BuckPrologCompiler.java b/lib/prolog/java/BuckPrologCompiler.java
index b731ea7..f761ea8 100644
--- a/lib/prolog/java/BuckPrologCompiler.java
+++ b/lib/prolog/java/BuckPrologCompiler.java
@@ -20,19 +20,10 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Arrays;
import java.util.List;
-import java.util.Locale;
import java.util.jar.JarEntry;
import java.util.jar.JarOutputStream;
-import javax.tools.Diagnostic;
-import javax.tools.DiagnosticCollector;
-import javax.tools.JavaCompiler;
-import javax.tools.JavaFileObject;
-import javax.tools.StandardJavaFileManager;
-import javax.tools.ToolProvider;
-
public class BuckPrologCompiler {
public static void main(String[] argv) throws IOException, CompileException {
List<File> srcs = new ArrayList<File>();
@@ -48,12 +39,10 @@
File out = new File(argv[argv.length - 1]);
File java = tmpdir("java");
- File classes = tmpdir("classes");
for (File src : srcs) {
new Compiler().prologToJavaSource(src.getPath(), java.getPath());
}
- javac(jars, java, classes);
- jar(out, classes);
+ jar(out, java);
}
private static File tmpdir(String name) throws IOException {
@@ -64,59 +53,11 @@
return d;
}
- private static void javac(List<File> cp, File java, File classes)
- throws IOException, CompileException {
- JavaCompiler javac = ToolProvider.getSystemJavaCompiler();
- if (javac == null) {
- throw new CompileException("JDK required (running inside of JRE)");
- }
-
- DiagnosticCollector<JavaFileObject> d =
- new DiagnosticCollector<JavaFileObject>();
- StandardJavaFileManager fm = javac.getStandardFileManager(d, null, null);
- try {
- StringBuilder classpath = new StringBuilder();
- for (File jar : cp) {
- if (classpath.length() > 0) {
- classpath.append(File.pathSeparatorChar);
- }
- classpath.append(jar.getPath());
- }
- ArrayList<String> args = new ArrayList<String>();
- args.addAll(Arrays.asList(new String[]{
- "-source", "6",
- "-target", "6",
- "-g:none",
- "-nowarn",
- "-d", classes.getPath()}));
- if (classpath.length() > 0) {
- args.add("-classpath");
- args.add(classpath.toString());
- }
- if (!javac.getTask(null, fm, d, args, null,
- fm.getJavaFileObjectsFromFiles(find(java, ".java"))).call()) {
- StringBuilder msg = new StringBuilder();
- for (Diagnostic<? extends JavaFileObject> err : d.getDiagnostics()) {
- msg.append('\n').append(err.getKind()).append(": ");
- if (err.getSource() != null) {
- msg.append(err.getSource().getName());
- }
- msg.append(':').append(err.getLineNumber()).append(": ");
- msg.append(err.getMessage(Locale.getDefault()));
- }
- throw new CompileException(msg.toString());
- }
- } finally {
- fm.close();
- }
- }
-
private static void jar(File jar, File classes) throws IOException {
File tmp = File.createTempFile("prolog", ".jar", jar.getParentFile());
try {
JarOutputStream out = new JarOutputStream(new FileOutputStream(tmp));
try {
- out.setLevel(9);
add(out, classes, "");
} finally {
out.close();
@@ -154,16 +95,4 @@
}
}
}
-
- private static List<File> find(File dir, String extension) {
- ArrayList<File> list = new ArrayList<File>();
- for (File f : dir.listFiles()) {
- if (f.getName().endsWith(extension)) {
- list.add(f);
- } else if (f.isDirectory()) {
- list.addAll(find(f, extension));
- }
- }
- return list;
- }
}