xf86-video-omapfb: pandora: handle cycle/forcer events better
[openembedded.git] / classes / gitver.bbclass
1 # Copyright (C) 2009 Chris Larson <clarson@kergoth.com>
2 # Released under the MIT license (see COPYING.MIT for the terms)
3 #
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.
7
8
9 GITVER = "${@get_git_pv('${S}', d)}"
10
11 def get_git_pv(path, d, tagadjust=None):
12     from subprocess import Popen, PIPE
13     import os
14     from bb import error
15     from bb.parse import mark_dependency
16
17     gitdir = os.path.abspath(os.path.join(d.getVar("S", True), ".git"))
18     env = { "GIT_DIR": gitdir }
19
20     def popen(cmd, **kwargs):
21         kwargs["stderr"] = PIPE
22         kwargs["stdout"] = PIPE
23         kwargs["env"] = env
24         try:
25             pipe = Popen(cmd, **kwargs)
26         except OSError, e:
27             #error("Execution of %s failed: %s" % (cmd, e))
28             return
29
30         (stdout, stderr) = pipe.communicate(None)
31         if pipe.returncode != 0:
32             #error("Execution of %s failed: %s" % (cmd, stderr))
33             return
34         return stdout.rstrip()
35
36     # Force the recipe to be reparsed so the version gets bumped
37     # if the active branch is switched, or if the branch changes.
38     mark_dependency(d, os.path.join(gitdir, "HEAD"))
39
40     ref = popen(["git", "symbolic-ref", "HEAD"])
41     reffile = os.path.join(gitdir, ref)
42     if ref and os.path.exists(reffile):
43         mark_dependency(d, reffile)
44     else:
45         # The ref might be hidden in packed-refs. Force a reparse if anything
46         # in the working copy changes.
47         mark_dependency(d, os.path.join(gitdir, "index"))
48
49     # Catch new tags.
50     tagdir = os.path.join(gitdir, "refs", "tags")
51     if os.path.exists(tagdir):
52         mark_dependency(d, tagdir)
53
54     ver = popen(["git", "describe", "--tags"], cwd=path)
55     if not ver:
56         ver = popen(["git", "rev-parse", "--short", "HEAD"], cwd=path)
57         if ver:
58             return "0.0-%s" % ver
59         else:
60             return "0.0"
61     else:
62         if tagadjust:
63             ver = tagadjust(ver)
64         return ver