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.
8 def git_drop_tag_prefix(version):
10 if re.match("v\d", version):
15 GIT_TAGADJUST = "git_drop_tag_prefix(version)"
16 GITVER = "${@get_git_pv('${S}', d, tagadjust=lambda version:${GIT_TAGADJUST})}"
17 GITSHA = "${@get_git_hash('${S}', d)}"
19 def get_git_hash(path, d):
20 return oe_run(d, ["git", "rev-parse", "--short", "HEAD"], cwd=path).rstrip()
22 def get_git_pv(path, d, tagadjust=None):
26 gitdir = os.path.abspath(os.path.join(d.getVar("S", True), ".git"))
29 return oe_run(d, ["git"] + cmd, cwd=gitdir).rstrip()
30 except oe.process.CmdError, exc:
34 ver = oe_run(d, ["git", "describe", "--tags"], cwd=gitdir).rstrip()
35 except Exception, exc:
40 ver = get_git_hash(gitdir, d)
41 except Exception, exc:
53 def mark_recipe_dependencies(path, d):
54 from bb.parse import mark_dependency
56 gitdir = os.path.join(path, ".git")
58 # Force the recipe to be reparsed so the version gets bumped
59 # if the active branch is switched, or if the branch changes.
60 mark_dependency(d, os.path.join(gitdir, "HEAD"))
62 # Force a reparse if anything in the index changes.
63 mark_dependency(d, os.path.join(gitdir, "index"))
66 ref = oe_run(d, ["git", "symbolic-ref", "-q", "HEAD"], cwd=gitdir).rstrip()
67 except oe.process.CmdError:
71 mark_dependency(d, os.path.join(gitdir, ref))
74 tagdir = os.path.join(gitdir, "refs", "tags")
75 if os.path.exists(tagdir):
76 mark_dependency(d, tagdir)
79 mark_recipe_dependencies(d.getVar("S", True), d)