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