[oe-commits] Chris Larson : gitver.bbclass: add initial version.

git version control git at git.openembedded.org
Wed Aug 26 03:01:59 UTC 2009


Module: openembedded.git
Branch: org.openembedded.dev
Commit: e5b751653cb17d60665a648c8f9aaeda028aa122
URL:    http://gitweb.openembedded.net/?p=openembedded.git&a=commit;h=e5b751653cb17d60665a648c8f9aaeda028aa122

Author: Chris Larson <clarson at kergoth.com>
Date:   Wed Aug 26 03:59:25 2009 -0700

gitver.bbclass: add initial version.

This provides a GITVER variable which is a (fairly) sane version, for use in
${PV}, extracted from the ${S} git checkout, assuming it is one.  This is most
useful in concert with srctree.bbclass.

Signed-off-by: Chris Larson <clarson at kergoth.com>

---

 classes/gitver.bbclass |   54 ++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 54 insertions(+), 0 deletions(-)

diff --git a/classes/gitver.bbclass b/classes/gitver.bbclass
new file mode 100644
index 0000000..92c053a
--- /dev/null
+++ b/classes/gitver.bbclass
@@ -0,0 +1,54 @@
+# Copyright (C) 2009 Chris Larson <clarson at kergoth.com>
+# Released under the MIT license (see COPYING.MIT for the terms)
+#
+# gitver.bbclass provides a GITVER variable which is a (fairly) sane version,
+# for use in ${PV}, extracted from the ${S} git checkout, assuming it is one.
+# This is most useful in concert with srctree.bbclass.
+
+
+GITVER = "${@get_git_pv('${S}', d)}"
+
+def gitver_mark_dependency(d):
+    from bb.data import expand
+    from bb.parse import mark_dependency
+    from os.path import abspath
+
+    fn = abspath(expand("${S}/.git/HEAD", d))
+    mark_dependency(d, fn)
+
+def get_git_pv(path, d, tagadjust=None):
+    from subprocess import Popen, PIPE
+    from os.path import join
+    from bb import error
+
+    env = {"GIT_DIR": join(d.getVar("S", True), ".git")}
+
+    def popen(cmd, **kwargs):
+        kwargs["stderr"] = PIPE
+        kwargs["stdout"] = PIPE
+        kwargs["env"] = env
+        try:
+            pipe = Popen(cmd, **kwargs)
+        except OSError, e:
+            #error("Execution of %s failed: %s" % (cmd, e))
+            return
+
+        (stdout, stderr) = pipe.communicate(None)
+        if pipe.returncode != 0:
+            #error("Execution of %s failed: %s" % (cmd, stderr))
+            return
+        return stdout.rstrip()
+
+    gitver_mark_dependency(d)
+
+    ver = popen(["git", "describe", "--tags"], cwd=path)
+    if not ver:
+        ver = popen(["git", "rev-parse", "--short", "HEAD"], cwd=path)
+        if ver:
+            return "0.0-%s" % ver
+        else:
+            return "0.0"
+    else:
+        if tagadjust:
+            ver = tagadjust(ver)
+        return ver





More information about the Openembedded-commits mailing list