From a0c9372baac8a242d68e4e48e7c7f54440e5b3eb Mon Sep 17 00:00:00 2001 From: Shawn Pearce Date: Fri, 10 May 2013 11:20:55 -0700 Subject: [PATCH] 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 --- gerrit-common/BUCK | 13 ++++++++++++- gerrit-gwtexpui/BUCK | 2 +- gerrit-war/BUCK | 3 +-- plugins/BUCK | 4 ++-- 4 files changed, 16 insertions(+), 6 deletions(-) diff --git a/gerrit-common/BUCK b/gerrit-common/BUCK index 3e7b73c78c..7423e35976 100644 --- a/gerrit-common/BUCK +++ b/gerrit-common/BUCK @@ -36,9 +36,20 @@ java_library( 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 199e216aa6..4e6774d2cd 100644 --- a/gerrit-gwtexpui/BUCK +++ b/gerrit-gwtexpui/BUCK @@ -16,7 +16,7 @@ gwt_module( 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 5c1f9f8ee1..c5fec87874 100644 --- a/gerrit-war/BUCK +++ b/gerrit-war/BUCK @@ -17,8 +17,7 @@ java_library( 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 707b38ebac..ded6ba2593 100644 --- a/plugins/BUCK +++ b/plugins/BUCK @@ -25,9 +25,9 @@ genrule( 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],