1 # Copyright (C) 2009 Chris Larson <clarson@kergoth.com>
2 # Released under the MIT license (see COPYING.MIT for the terms)
4 # gitver.bbclass provides a GITVER variable which is a (fairly) sane version,
5 # for use in ${PV}, extracted from the ${S} git checkout, assuming it is one.
6 # This is most useful in concert with srctree.bbclass.
9 GITVER = "${@get_git_pv('${S}', d)}"
11 def gitver_mark_dependency(d):
12 from bb.data import expand
13 from bb.parse import mark_dependency
14 from os.path import abspath
16 fn = abspath(expand("${S}/.git/HEAD", d))
17 mark_dependency(d, fn)
19 def get_git_pv(path, d, tagadjust=None):
20 from subprocess import Popen, PIPE
21 from os.path import join
24 env = {"GIT_DIR": join(d.getVar("S", True), ".git")}
26 def popen(cmd, **kwargs):
27 kwargs["stderr"] = PIPE
28 kwargs["stdout"] = PIPE
31 pipe = Popen(cmd, **kwargs)
33 #error("Execution of %s failed: %s" % (cmd, e))
36 (stdout, stderr) = pipe.communicate(None)
37 if pipe.returncode != 0:
38 #error("Execution of %s failed: %s" % (cmd, stderr))
40 return stdout.rstrip()
42 gitver_mark_dependency(d)
44 ver = popen(["git", "describe", "--tags"], cwd=path)
46 ver = popen(["git", "rev-parse", "--short", "HEAD"], cwd=path)