Support for automatic package versining using git describe
Hi
Quoted 8 lines · On Fri, 13 Feb 2009 00:32:21 -0200 Otavio Salvador <[email protected]>…
One of nice features we've been using is the git-describe to get versions based on tags; many projects are using it to name the development releases and it does give a better view of how diverged it from last released version.
So we're looking for a way to use it to generate the PV based on that. The current git fetcher already has the required support to get tags, so we can use it as SRCREV, but not yet to use git-describe.
Attached is an attempt to implement this idea. One could use bb.fetch.describe_revision for, say, AUTOPV generation, like bb.fetch.get_srcrev is used for AUTOREV.
Example (from bitbake.conf):
AUTOREV = "${@bb.fetch.get_srcrev(d)}"
AUTOPV = "${@bb.fetch.describe_revision(d)}"It would be nice if somebody could review the attached patch, since I don't know much about bitbake internals.
P.S.: sorry if this message is messing up threading in your email client. I'm replying to a fake original message, since I don't have the original one.
Best wishes.
Mario
bb/fetch/__init__.py +30 -13
@@ -196,6 +196,20 @@ srcrev_internal_call = False +def get_scms(d, urldata, rev_support_only = True): + scms = [] + for u in urldata: + ud = urldata[u] + if rev_support_only or ud.method.suppports_srcrev(): + if not ud.setup: + ud.setup_localpath(d) + scms.append(u) + + if len(scms) == 0: + bb.msg.error(bb.msg.domain.Fetcher, "SRCREV was used yet no valid SCM was found in SRC_URI") + + return scms + def get_srcrev(d): """ Return the version string for the current package
@@ -217,21 +231,9 @@ if bb.fetch.srcrev_internal_call: return "SRCREVINACTION" - scms = [] - - # Only call setup_localpath on URIs which suppports_srcrev() urldata = init(bb.data.getVar('SRC_URI', d, 1).split(), d, False) - for u in urldata: - ud = urldata[u] - if ud.method.suppports_srcrev(): - if not ud.setup: - ud.setup_localpath(d) - scms.append(u) + scms = get_scms(d, urldata) - if len(scms) == 0: - bb.msg.error(bb.msg.domain.Fetcher, "SRCREV was used yet no valid SCM was found in SRC_URI") - raise ParameterError - bb.data.setVar('__BB_DONT_CACHE','1', d) if len(scms) == 1:
@@ -253,6 +255,21 @@ return format +def describe_revision(d): + urldata = init(bb.data.getVar('SRC_URI', d, 1).split(), d, False) + bb.data.setVar('__BB_DONT_CACHE','1', d) + scms = get_scms(d, urldata) + scm = '' + if len(scms) == 1: + scm = scms[0] + else: + bb.msg.error(bb.msg.domain.Fetcher, "describe_revision does not support multiple SCMs.") + + try: + return urldata[scm].method.describe_revision(scm, urldata[scm], d) + except NoMethodError: + return "NO_REV_DESCR" + def localpath(url, d, cache = True): """ Called from the parser with cache=False since the cache isn't ready
bb/fetch/git.py +37 -9
72 lines not on this page · raw message
Mario Domenech Goulart <[email protected]> writes:
[...]
Quoted 8 lines
Index:
lib/bb/fetch/git.py
===================================================================bb/fetch/git.py +0
-0@@ -42,11 +42,12 @@ ud.proto = ud.parm['protocol'] ud.branch = ud.parm.get("branch", "master")
bb/fetch/git.py line 53
Quoted 10 lines
bb/fetch/git.py +2
-1+ ud.tag = None tag = Fetch.srcrev_internal_helper(ud, d) if tag is True: ud.tag = self.latest_revision(url, ud, d) - elif tag: + elif tag and tag != "1": ud.tag = tag if not ud.tag or ud.tag == "master":
[...]
Please drop this hook since it is our internal workaround for the lack of the AUTOREV in our recipes.
Signature · 3 lines
Otavio Salvador O.S. Systems E-mail: [email protected] http://www.ossystems.com.br Mobile: +55 53 9981-7854 http://projetos.ossystems.com.br
Quoted 19 lines · On Thu, 05 Mar 2009 10:43:04 -0300 Otavio Salvador <[email protected]>…
Quoted 17 lines · Mario Domenech Goulart
Index:
lib/bb/fetch/git.py
===================================================================bb/fetch/git.py +2
-1@@ -42,11 +42,12 @@ ud.proto = ud.parm['protocol'] ud.branch = ud.parm.get("branch", "master") + ud.tag = None tag = Fetch.srcrev_internal_helper(ud, d) if tag is True: ud.tag = self.latest_revision(url, ud, d) - elif tag: + elif tag and tag != "1": ud.tag = tag
Quoted 6 lines
bb/fetch/git.py line 53
Quoted 1 line
bb/fetch/git.py +0
-0if not ud.tag or ud.tag == "master":[...]
Please drop this hook since it is our internal workaround for the lack of the AUTOREV in our recipes.
Sure. Attached is the new patch.
Best wishes.
Mario
bb/fetch/__init__.py +34 -13
@@ -196,6 +196,20 @@ srcrev_internal_call = False +def get_scms(d, urldata, rev_support_only = True): + scms = [] + for u in urldata: + ud = urldata[u] + if rev_support_only or ud.method.suppports_srcrev(): + if not ud.setup: + ud.setup_localpath(d) + scms.append(u) + + if len(scms) == 0: + bb.msg.error(bb.msg.domain.Fetcher, "SRCREV was used yet no valid SCM was found in SRC_URI") + + return scms + def get_srcrev(d): """ Return the version string for the current package
@@ -217,21 +231,9 @@ if bb.fetch.srcrev_internal_call: return "SRCREVINACTION" - scms = [] - - # Only call setup_localpath on URIs which suppports_srcrev() urldata = init(bb.data.getVar('SRC_URI', d, 1).split(), d, False) - for u in urldata: - ud = urldata[u] - if ud.method.suppports_srcrev(): - if not ud.setup: - ud.setup_localpath(d) - scms.append(u) + scms = get_scms(d, urldata) - if len(scms) == 0: - bb.msg.error(bb.msg.domain.Fetcher, "SRCREV was used yet no valid SCM was found in SRC_URI") - raise ParameterError - bb.data.setVar('__BB_DONT_CACHE','1', d) if len(scms) == 1:
@@ -253,6 +255,25 @@ return format +def describe_revision(d): + """ + Return the output of 'git describe' or 'NO_REV_DESCR' in case no + tag is found. + """ + urldata = init(bb.data.getVar('SRC_URI', d, 1).split(), d, False) + bb.data.setVar('__BB_DONT_CACHE','1', d) + scms = get_scms(d, urldata) + scm = '' + if len(scms) == 1: + scm = scms[0] + else: + bb.msg.error(bb.msg.domain.Fetcher, "describe_revision does not support multiple SCMs.") + + try: + return urldata[scm].method.describe_revision(scm, urldata[scm], d) + except NoMethodError: + return "NO_REV_DESCR" + def localpath(url, d, cache = True): """ Called from the parser with cache=False since the cache isn't ready
bb/fetch/git.py +31 -8
@@ -141,6 +141,16 @@ def _want_sortable_revision(self, url, ud, d): return bb.data.getVar("BB_GIT_CLONE_FOR_SRCREV", d, True) or False + def _chrepo(self, repodir, ud, d): + # Check if we have the rev already + if not os.path.exists(repodir): + print "no repo" + self.go(None, ud, d) + + os.chdir(repodir) + if not self._contains_ref(ud.tag, d): + self.go(None, ud, d) + def _sortable_revision(self, url, ud, d): """ This is only called when _want_sortable_revision called true
@@ -162,15 +172,8 @@ cwd = os.getcwd() - # Check if we have the rev already - if not os.path.exists(repodir): - print "no repo" - self.go(None, ud, d) + self._chrepo(repodir, ud, d) - os.chdir(repodir) - if not self._contains_ref(ud.tag, d): - self.go(None, ud, d) - output = runfetchcmd("git rev-list %s -- 2> /dev/null | wc -l" % ud.tag, d, quiet=True) os.chdir(cwd)
@@ -179,3 +182,23 @@ return sortable_revision + def describe_revision(self, url, ud, d): + gitsrcname = '%s%s' % (ud.host, ud.path.replace('/', '.')) + repodir = os.path.join(data.expand('${GITDIR}', d), gitsrcname) + + # Runtime warning on wrongly configured sources + if ud.tag == "1": + bb.msg.error(1, bb.msg.domain.Fetcher, "SRCREV is '1'. This indicates a configuration error of %s" % url) + return "0+1" + + cwd = os.getcwd() + + self._chrepo(repodir, ud, d) + + rev_descr = '' + try: + rev_descr = runfetchcmd("git describe 2>/dev/null", d, quiet=True).strip() + except FetchError: + rev_descr = "NO_REV_DESCR" + os.chdir(cwd) + return rev_descr
Sorry for top-posting, but I can't find a good point to hook into.
I have a few general questions:
1) what happens when DLDIR and TMPDIR are empty (e.g. first build)
2) does it need a netconnections at any point?
3) do you have any examples how output looks before and after your patch?
I'd also like to hear RPs and zeckes opinion in this
regards,
Koen
Quoted 40 lines · Mario Domenech Goulart
Quoted 19 lines · On Thu, 05 Mar 2009 10:43:04 -0300 Otavio Salvador<[email protected]>…
Quoted 17 lines · Mario Domenech Goulart
Index:
lib/bb/fetch/git.py
===================================================================bb/fetch/git.py +2
-1@@ -42,11 +42,12 @@ ud.proto = ud.parm['protocol'] ud.branch = ud.parm.get("branch", "master") + ud.tag = None tag = Fetch.srcrev_internal_helper(ud, d) if tag is True: ud.tag = self.latest_revision(url, ud, d) - elif tag: + elif tag and tag != "1": ud.tag = tagQuoted 5 lines
bb/fetch/git.py line 53
Quoted 1 line
bb/fetch/git.py +0
-0if not ud.tag or ud.tag == "master":[...]
Please drop this hook since it is our internal workaround for the lack of the AUTOREV in our recipes.
Sure. Attached is the new patch.
Best wishes.
Mario------------------------------------------------------------------------
_______________________________________________
Openembedded-devel mailing list
[email protected]
http://lists.linuxtogo.org/cgi-bin/mailman/listinfo/openembedded-devel
Quoted 5 lines · Mario Domenech Goulart
Quoted 2 lines · On Thu, 05 Mar 2009 10:43:04 -0300 Otavio Salvador <[email protected]>…
Please drop this hook since it is our internal workaround for the lack of the AUTOREV in our recipes.
Sure. Attached is the new patch.
I don't know the context for these patches, so please forgive me if I should be reading the sources instead of asking here (perhaps my question makes no sense at all):
What does this code do if I make a tarball snapshot of the "openembedded" directory structure, excluding the .git directory, and attempt to build from that?
-Mike (mwester)