[oe-commits] Chris Larson : gitver: add GITSHA variable
git version control
git at git.openembedded.org
Thu Oct 28 00:28:44 UTC 2010
Module: openembedded.git
Branch: master
Commit: 8264858d8c038030dcbd713cfad1f564c10e1e84
URL: http://gitweb.openembedded.net/?p=openembedded.git&a=commit;h=8264858d8c038030dcbd713cfad1f564c10e1e84
Author: Chris Larson <chris_larson at mentor.com>
Date: Wed Oct 27 17:22:38 2010 -0700
gitver: add GITSHA variable
There's a case where git describe produces output which is not pleasant, to
put it mildly, and it's better to just set PV to "0.0+${GITSHA}" or similar,
including the short form of the commit hash for HEAD.
Signed-off-by: Chris Larson <chris_larson at mentor.com>
---
classes/gitver.bbclass | 45 ++++++++++++++++++++++++++++++++-------------
1 files changed, 32 insertions(+), 13 deletions(-)
diff --git a/classes/gitver.bbclass b/classes/gitver.bbclass
index 28256c6..ee8323d 100644
--- a/classes/gitver.bbclass
+++ b/classes/gitver.bbclass
@@ -14,11 +14,13 @@ def git_drop_tag_prefix(version):
GIT_TAGADJUST = "git_drop_tag_prefix(version)"
GITVER = "${@get_git_pv('${S}', d, tagadjust=lambda version:${GIT_TAGADJUST})}"
+GITSHA = "${@get_git_hash('${S}', d)}"
+
+def get_git_hash(path, d):
+ return oe_run(d, ["git", "rev-parse", "--short", "HEAD"], cwd=path).rstrip()
def get_git_pv(path, d, tagadjust=None):
import os
- from bb import error
- from bb.parse import mark_dependency
import oe.process
gitdir = os.path.abspath(os.path.join(d.getVar("S", True), ".git"))
@@ -28,6 +30,31 @@ def get_git_pv(path, d, tagadjust=None):
except oe.process.CmdError, exc:
bb.fatal(str(exc))
+ try:
+ ver = oe_run(d, ["git", "describe", "--tags"], cwd=gitdir).rstrip()
+ except Exception, exc:
+ bb.fatal(str(exc))
+
+ if not ver:
+ try:
+ ver = get_git_hash(gitdir, d)
+ except Exception, exc:
+ bb.fatal(str(exc))
+
+ if ver:
+ return "0.0+%s" % ver
+ else:
+ return "0.0"
+ else:
+ if tagadjust:
+ ver = tagadjust(ver)
+ return ver
+
+def mark_recipe_dependencies(path, d):
+ from bb.parse import mark_dependency
+
+ gitdir = os.path.join(path, ".git")
+
# Force the recipe to be reparsed so the version gets bumped
# if the active branch is switched, or if the branch changes.
mark_dependency(d, os.path.join(gitdir, "HEAD"))
@@ -48,14 +75,6 @@ def get_git_pv(path, d, tagadjust=None):
if os.path.exists(tagdir):
mark_dependency(d, tagdir)
- ver = git(["describe", "--tags"])
- if not ver:
- ver = git(["rev-parse", "--short", "HEAD"])
- if ver:
- return "0.0-%s" % ver
- else:
- return "0.0"
- else:
- if tagadjust:
- ver = tagadjust(ver)
- return ver
+python () {
+ mark_recipe_dependencies(d.getVar("S", True), d)
+}
More information about the Openembedded-commits
mailing list