Minor cleanups on BUCK genrules

Assume BUCK has applied my commit to use set -e when running a
genrule(). This allows us to use ';' in all genrule commands and
trust the build will stop if any of the single statement terminates
with a non-zero exit status.

$SRCDIR is a cleaner reference to the sources of a genrule(),
fixing an ugly reference to the (supposedly hidden) __srcs directory.

Add a comment about the version generator, BUCK wants to make genrule
output fully cacheable, which requires rules to be idempotent.

Change-Id: I938450ed81675330e979d76721e0ba971d30d0e2
diff --git a/gerrit-common/BUCK b/gerrit-common/BUCK
index 3e7b73c..7423e35 100644
--- a/gerrit-common/BUCK
+++ b/gerrit-common/BUCK
@@ -36,9 +36,20 @@
   visibility = ['PUBLIC'],
 )
 
+# TODO(sop): Move git describe into an uncacheable genrule()
+def git_describe():
+  import subprocess
+  cmd = ['git', 'describe', 'HEAD']
+  p = subprocess.Popen(cmd, stdout = subprocess.PIPE)
+  v = p.communicate()[0].strip()
+  r = p.returncode
+  if r != 0:
+    raise subprocess.CalledProcessError(r, ' '.join(cmd))
+  return v
+
 genrule(
   name = 'git_describe',
-  cmd = 'mkdir -p $(dirname $OUT); git describe HEAD >$OUT',
+  cmd = 'mkdir -p $(dirname $OUT); echo "%s" >$OUT' % git_describe(),
   srcs = [],
   out = VER,
 )
diff --git a/gerrit-gwtexpui/BUCK b/gerrit-gwtexpui/BUCK
index 199e216..4e6774d 100644
--- a/gerrit-gwtexpui/BUCK
+++ b/gerrit-gwtexpui/BUCK
@@ -16,7 +16,7 @@
 
 genrule(
   name = 'clippy_swf',
-  cmd = 'mkdir $TMP/gerrit_ui ;' +
+  cmd = 'mkdir $TMP/gerrit_ui;' +
     'cp $SRCS $TMP/gerrit_ui;' +
     'cd $TMP;' +
     'zip -qr $OUT gerrit_ui',
diff --git a/gerrit-war/BUCK b/gerrit-war/BUCK
index 5c1f9f8..c5fec87 100644
--- a/gerrit-war/BUCK
+++ b/gerrit-war/BUCK
@@ -17,8 +17,7 @@
 
 genrule(
   name = 'webapp_assets',
-  cmd = 'cd $(dirname $OUT)/webapp_assets__srcs/src/main/webapp && ' +
-    'zip -qr $OUT .',
+  cmd = 'cd $SRCDIR/src/main/webapp; zip -qr $OUT .',
   srcs = glob(['src/main/webapp/**/*']),
   deps = [],
   out = 'webapp_assets.zip',
diff --git a/plugins/BUCK b/plugins/BUCK
index 707b38e..ded6ba2 100644
--- a/plugins/BUCK
+++ b/plugins/BUCK
@@ -25,9 +25,9 @@
   cmd = '' +
     ';'.join(['echo >&2 plugins/'+n+' is required.' for n in NEED]) +
     (';echo >&2;exit 1;' if NEED else '') +
-    'mkdir -p $TMP/WEB-INF/plugins &&' +
+    'mkdir -p $TMP/WEB-INF/plugins;' +
     'for s in $SRCS;do ln -s $s $TMP/WEB-INF/plugins;done;' +
-    'cd $TMP &&' +
+    'cd $TMP;' +
     'zip -qr $OUT .',
   srcs = [genfile('%s/%s.jar' % (n, n)) for n in CORE],
   deps = ['//%s/%s:%s' % (BASE, n, n) for n in HAVE],