diff options
| author | Martin Jansa <Martin.Jansa@gmail.com> | 2011-04-10 13:24:47 +0200 |
|---|---|---|
| committer | Martin Jansa <Martin.Jansa@gmail.com> | 2011-04-10 14:43:41 +0200 |
| commit | 89500c583e0f1dc1b4ffdf72914e08e505e427e0 (patch) | |
| tree | b073036cc61aa34ca5ac9eec4d617366e0dcb3d5 /meta-oe/classes/gitpkgv.bbclass | |
| parent | e66079da37992abd54486488aa06a99bf7a4198c (diff) | |
| download | meta-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/gitpkgv.bbclass')
| -rw-r--r-- | meta-oe/classes/gitpkgv.bbclass | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/meta-oe/classes/gitpkgv.bbclass b/meta-oe/classes/gitpkgv.bbclass new file mode 100644 index 0000000000..bedceb9d6e --- /dev/null +++ b/meta-oe/classes/gitpkgv.bbclass | |||
| @@ -0,0 +1,84 @@ | |||
| 1 | # gitpkgv.bbclass provides a GITPKGV and GITPKGVTAG variables to be | ||
| 2 | # used in PKGV, as described bellow: | ||
| 3 | # | ||
| 4 | # - GITPKGV which is a sortable version with the format NN+GITHASH, to | ||
| 5 | # be used in PKGV, where | ||
| 6 | # | ||
| 7 | # NN equals the total number of revs up to SRCREV | ||
| 8 | # GITHASH is SRCREV's (full) hash | ||
| 9 | # | ||
| 10 | # - GITPKGVTAG which is the output of 'git describe' allowing for | ||
| 11 | # automatic versioning | ||
| 12 | # | ||
| 13 | # gitpkgv.bbclass assumes the git repository has been cloned, and | ||
| 14 | # contains SRCREV. So ${GITPKGV} and ${GITPKGVTAG} should never be | ||
| 15 | # used in PV, only in PKGV. It can handle SRCREV = ${AUTOREV}, as | ||
| 16 | # well as SRCREV = "<some fixed git hash>". | ||
| 17 | # | ||
| 18 | # WARNING: if upstream repository is always using consistent and | ||
| 19 | # sortable tag name scheme you can get sortable version including tag | ||
| 20 | # name with ${GITPKGVTAG}, but be aware that ie tag sequence "v1.0, | ||
| 21 | # v1.2, xtest, v2.0" will force you to increment PE to get upgradeable | ||
| 22 | # path to v2.0 revisions | ||
| 23 | # | ||
| 24 | # use example: | ||
| 25 | # | ||
| 26 | # inherit gitpkgv | ||
| 27 | # | ||
| 28 | # PV = "1.0+gitr${SRCPV}" # expands to something like 1.0+gitr3+4c1c21d7dbbf93b0df336994524313dfe0d4963b | ||
| 29 | # PKGV = "1.0+gitr${GITPKGV}" # expands also to something like 1.0+gitr31337+4c1c21d7d | ||
| 30 | # | ||
| 31 | # or | ||
| 32 | # | ||
| 33 | # inherit gitpkgv | ||
| 34 | # | ||
| 35 | # PV = "1.0+gitr${SRCPV}" # expands to something like 1.0+gitr3+4c1c21d7dbbf93b0df336994524313dfe0d4963b | ||
| 36 | # PKGV = "${GITPKGVTAG}" # expands to something like 1.0-31337+g4c1c21d | ||
| 37 | # if there is tag v1.0 before this revision or | ||
| 38 | # ver1.0-31337+g4c1c21d if there is tag ver1.0 | ||
| 39 | |||
| 40 | GITPKGV = "${@get_git_pkgv(d, False)}" | ||
| 41 | GITPKGVTAG = "${@get_git_pkgv(d, True)}" | ||
| 42 | |||
| 43 | def gitpkgv_drop_tag_prefix(version): | ||
| 44 | import re | ||
| 45 | if re.match("v\d", version): | ||
| 46 | return version[1:] | ||
| 47 | else: | ||
| 48 | return version | ||
| 49 | |||
| 50 | def get_git_pkgv(d, use_tags): | ||
| 51 | import os | ||
| 52 | import bb | ||
| 53 | |||
| 54 | urls = bb.data.getVar('SRC_URI', d, 1).split() | ||
| 55 | |||
| 56 | for url in urls: | ||
| 57 | (type, host, path, user, pswd, parm) = bb.decodeurl(bb.data.expand(url, d)) | ||
| 58 | if type in ['git']: | ||
| 59 | |||
| 60 | gitsrcname = '%s%s' % (host, path.replace('/', '.')) | ||
| 61 | repodir = os.path.join(bb.data.expand('${GITDIR}', d), gitsrcname) | ||
| 62 | if not os.path.exists(repodir): | ||
| 63 | return None | ||
| 64 | |||
| 65 | rev = bb.fetch.get_srcrev(d).split('+')[1] | ||
| 66 | |||
| 67 | cwd = os.getcwd() | ||
| 68 | os.chdir(repodir) | ||
| 69 | |||
| 70 | commits = bb.fetch.runfetchcmd("git rev-list %s -- 2> /dev/null | wc -l" % rev, d, quiet=True).strip() | ||
| 71 | |||
| 72 | if use_tags: | ||
| 73 | try: | ||
| 74 | ver = gitpkgv_drop_tag_prefix(bb.fetch.runfetchcmd("git describe %s 2>/dev/null" % rev, d, quiet=True).strip()) | ||
| 75 | except Exception: | ||
| 76 | ver = "0.0-%s-g%s" % (commits, rev[:7]) | ||
| 77 | else: | ||
| 78 | ver = "%s+%s" % (commits, rev[:7]) | ||
| 79 | |||
| 80 | os.chdir(cwd) | ||
| 81 | |||
| 82 | return ver | ||
| 83 | |||
| 84 | return "0+0" | ||
