diff --git a/lib/bb/fetch/__init__.py b/lib/bb/fetch/__init__.py index 16c3a96..cf4bc2c 100644 --- a/lib/bb/fetch/__init__.py +++ b/lib/bb/fetch/__init__.py @@ -197,6 +197,20 @@ def localpaths(d): srcrev_internal_call = False +def get_scms(d, urldata, rev_support_only = True): + scms = [] + for u in urldata: + ud = urldata[u] + if not rev_support_only or (rev_support_only and 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 @@ -218,20 +232,8 @@ def get_srcrev(d): 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) - - 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 + scms = get_scms(d, urldata) bb.data.setVar('__BB_DONT_CACHE','1', d) @@ -254,6 +256,25 @@ def get_srcrev(d): 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 diff --git a/lib/bb/fetch/git.py b/lib/bb/fetch/git.py index 97cd0a2..e0a5400 100644 --- a/lib/bb/fetch/git.py +++ b/lib/bb/fetch/git.py @@ -149,6 +149,16 @@ class Git(Fetch): 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 @@ -170,14 +180,7 @@ class Git(Fetch): cwd = os.getcwd() - # 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) + self._chrepo(repodir, ud, d) output = runfetchcmd("git rev-list %s -- 2> /dev/null | wc -l" % ud.tag, d, quiet=True) os.chdir(cwd) @@ -187,3 +190,24 @@ class Git(Fetch): 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 %s 2>/dev/null" % ud.tag, d, quiet=True).strip() + except FetchError: + rev_descr = "0.0.0-%s-g%s" % (runfetchcmd("git rev-list %s -- 2> /dev/null | wc -l" % ud.tag, d, quiet=True).strip(), + runfetchcmd("git describe %s --always 2> /dev/null" % ud.tag, d, quiet=True).strip()) + os.chdir(cwd) + return rev_descr.replace('-', '.')