summaryrefslogtreecommitdiffstats
path: root/meta-oe/classes/gitver.bbclass
diff options
context:
space:
mode:
authorMartin Jansa <Martin.Jansa@gmail.com>2011-04-10 13:24:47 +0200
committerMartin Jansa <Martin.Jansa@gmail.com>2011-04-10 14:43:41 +0200
commit89500c583e0f1dc1b4ffdf72914e08e505e427e0 (patch)
treeb073036cc61aa34ca5ac9eec4d617366e0dcb3d5 /meta-oe/classes/gitver.bbclass
parente66079da37992abd54486488aa06a99bf7a4198c (diff)
downloadmeta-openembedded-89500c583e0f1dc1b4ffdf72914e08e505e427e0.tar.gz
recipes,classes: import a lot of recipes from meta-shr
* tested on shr-lite-image for om-gta02 and nokia900 (with meta-shr layer)
Diffstat (limited to 'meta-oe/classes/gitver.bbclass')
-rw-r--r--meta-oe/classes/gitver.bbclass80
1 files changed, 80 insertions, 0 deletions
diff --git a/meta-oe/classes/gitver.bbclass b/meta-oe/classes/gitver.bbclass
new file mode 100644
index 000000000..ee8323d6f
--- /dev/null
+++ b/meta-oe/classes/gitver.bbclass
@@ -0,0 +1,80 @@
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
8def git_drop_tag_prefix(version):
9 import re
10 if re.match("v\d", version):
11 return version[1:]
12 else:
13 return version
14
15GIT_TAGADJUST = "git_drop_tag_prefix(version)"
16GITVER = "${@get_git_pv('${S}', d, tagadjust=lambda version:${GIT_TAGADJUST})}"
17GITSHA = "${@get_git_hash('${S}', d)}"
18
19def get_git_hash(path, d):
20 return oe_run(d, ["git", "rev-parse", "--short", "HEAD"], cwd=path).rstrip()
21
22def get_git_pv(path, d, tagadjust=None):
23 import os
24 import oe.process
25
26 gitdir = os.path.abspath(os.path.join(d.getVar("S", True), ".git"))
27 def git(cmd):
28 try:
29 return oe_run(d, ["git"] + cmd, cwd=gitdir).rstrip()
30 except oe.process.CmdError, exc:
31 bb.fatal(str(exc))
32
33 try:
34 ver = oe_run(d, ["git", "describe", "--tags"], cwd=gitdir).rstrip()
35 except Exception, exc:
36 bb.fatal(str(exc))
37
38 if not ver:
39 try:
40 ver = get_git_hash(gitdir, d)
41 except Exception, exc:
42 bb.fatal(str(exc))
43
44 if ver:
45 return "0.0+%s" % ver
46 else:
47 return "0.0"
48 else:
49 if tagadjust:
50 ver = tagadjust(ver)
51 return ver
52
53def mark_recipe_dependencies(path, d):
54 from bb.parse import mark_dependency
55
56 gitdir = os.path.join(path, ".git")
57
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"))
61
62 # Force a reparse if anything in the index changes.
63 mark_dependency(d, os.path.join(gitdir, "index"))
64
65 try:
66 ref = oe_run(d, ["git", "symbolic-ref", "-q", "HEAD"], cwd=gitdir).rstrip()
67 except oe.process.CmdError:
68 pass
69 else:
70 if ref:
71 mark_dependency(d, os.path.join(gitdir, ref))
72
73 # Catch new tags.
74 tagdir = os.path.join(gitdir, "refs", "tags")
75 if os.path.exists(tagdir):
76 mark_dependency(d, tagdir)
77
78python () {
79 mark_recipe_dependencies(d.getVar("S", True), d)
80}