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
This commit is contained in:
Shawn Pearce 2013-05-10 11:20:55 -07:00
parent 57492bbaf6
commit a0c9372baa
4 changed files with 16 additions and 6 deletions

View File

@ -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,
)

View File

@ -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',

View File

@ -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',

View File

@ -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],