Skip to contentSkip to conversation

gitver.bbclass: fix git dependency tracking

PATCH In review Michael Smith 2 participants 2 messages Oct 26, 2009

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gitver.bbclass: fix git dependency tracking

.git/HEAD doesn't usually change on a commit, but the ref it points to (e.g. .git/refs/heads/master) should. Handle this and another couple of
cases: if a tag is added without a new commit, or if the ref is in packed-refs.

---
 classes/gitver.bbclass |   32 +++++++++++++++++++++-----------
 1 files changed, 21 insertions(+), 11 deletions(-)
classes/gitver.bbclass +21 -11
index 92c053a..5b4ba8d 100644
@@ -8,20 +8,14 @@
 
 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
+    import os
     from bb import error
+    from bb.parse import mark_dependency
 
-    env = {"GIT_DIR": join(d.getVar("S", True), ".git")}
+    gitdir = os.path.abspath(os.path.join(d.getVar("S", True), ".git"))
+    env = { "GIT_DIR": gitdir }
 
     def popen(cmd, **kwargs):
         kwargs["stderr"] = PIPE
@@ -39,7 +33,23 @@ def get_git_pv(path, d, tagadjust=None):
             return
         return stdout.rstrip()
 
-    gitver_mark_dependency(d)
+    # 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"))
+
+    ref = popen(["git", "symbolic-ref", "HEAD"])
+    reffile = os.path.join(gitdir, ref)
+    if ref and os.path.exists(reffile):
+        mark_dependency(d, reffile)
+    else:
+        # The ref might be hidden in packed-refs. Force a reparse if anything
+        # in the working copy changes.
+        mark_dependency(d, os.path.join(gitdir, "index"))
+
+    # Catch new tags.
+    tagdir = os.path.join(gitdir, "refs", "tags")
+    if os.path.exists(tagdir):
+        mark_dependency(d, tagdir)
 
     ver = popen(["git", "describe", "--tags"], cwd=path)
     if not ver:
Signature · 1 line
1.6.3
Acked-by on v1 1/1
#1 lore raw

Good catch, looks good.

Quoted 73 lines · Michael Smith

.git/HEAD doesn't usually change on a commit, but the ref it points to (e.g. .git/refs/heads/master) should. Handle this and another couple of
cases: if a tag is added without a new commit, or if the ref is in packed-refs.

---
 classes/gitver.bbclass |   32 +++++++++++++++++++++-----------

 1 files changed, 21 insertions(+), 11 deletions(-)
classes/gitver.bbclass +0 -0
index 92c053a..5b4ba8d 100644
@@ -8,20 +8,14 @@
 

 GITVER = "${@get_git_pv('${S}', d)}"

classes/gitver.bbclass +0 -8
-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
+    import os
    from bb import error
+    from bb.parse import mark_dependency

-    env = {"GIT_DIR": join(d.getVar("S", True), ".git")}
+    gitdir = os.path.abspath(os.path.join(d.getVar("S", True), ".git"))
+    env = { "GIT_DIR": gitdir }

    def popen(cmd, **kwargs):
        kwargs["stderr"] = PIPE

classes/gitver.bbclass +0 -0
@@ -39,7 +33,23 @@ def get_git_pv(path, d, tagadjust=None):

            return
        return stdout.rstrip()

-    gitver_mark_dependency(d)
+    # 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"))

classes/gitver.bbclass +14 -0
+
+    ref = popen(["git", "symbolic-ref", "HEAD"])
+    reffile = os.path.join(gitdir, ref)
+    if ref and os.path.exists(reffile):
+        mark_dependency(d, reffile)
+    else:
+        # The ref might be hidden in packed-refs. Force a reparse if anything
+        # in the working copy changes.
+        mark_dependency(d, os.path.join(gitdir, "index"))
+
+    # Catch new tags.
+    tagdir = os.path.join(gitdir, "refs", "tags")
+    if os.path.exists(tagdir):
+        mark_dependency(d, tagdir)

    ver = popen(["git", "describe", "--tags"], cwd=path) if not ver:
--
1.6.3

_______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel

Signature · 7 lines
Chris Larson
clarson at kergoth dot com
clarson at mvista dot com
Founder - BitBake, OpenEmbedded, OpenZaurus
Maintainer - Tslib
Software Engineer
MontaVista Software, Inc.