ti-dmai: pass c6accel location to makefile
[openembedded.git] / classes / gitver.bbclass
blobde182a09c6da5dd8c5c0371483dd86bca6fb92a7
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):
9     import re
10     if re.match("v\d", version):
11         return version[1:]
12     else:
13         return version
15 GIT_TAGADJUST = "git_drop_tag_prefix(version)"
16 GITVER = "${@get_git_pv('${S}', d, tagadjust=lambda version:${GIT_TAGADJUST})}"
18 def get_git_pv(path, d, tagadjust=None):
19     import os
20     from bb import error
21     from bb.parse import mark_dependency
22     import oe.process
24     gitdir = os.path.abspath(os.path.join(d.getVar("S", True), ".git"))
25     def git(cmd):
26         try:
27             return oe_run(d, ["git"] + cmd, cwd=gitdir).rstrip()
28         except oe.process.CmdError, exc:
29             bb.fatal(str(exc))
31     # Force the recipe to be reparsed so the version gets bumped
32     # if the active branch is switched, or if the branch changes.
33     mark_dependency(d, os.path.join(gitdir, "HEAD"))
35     ref = git(["symbolic-ref", "HEAD"])
36     if ref:
37         reffile = os.path.join(gitdir, ref)
38         if os.path.exists(reffile):
39             mark_dependency(d, reffile)
40         else:
41             mark_dependency(d, os.path.join(gitdir, "index"))
42     else:
43         # The ref might be hidden in packed-refs. Force a reparse if anything
44         # in the working copy changes.
45         mark_dependency(d, os.path.join(gitdir, "index"))
47     # Catch new tags.
48     tagdir = os.path.join(gitdir, "refs", "tags")
49     if os.path.exists(tagdir):
50         mark_dependency(d, tagdir)
52     ver = git(["describe", "--tags"])
53     if not ver:
54         ver = git(["rev-parse", "--short", "HEAD"])
55         if ver:
56             return "0.0-%s" % ver
57         else:
58             return "0.0"
59     else:
60         if tagadjust:
61             ver = tagadjust(ver)
62         return ver