summaryrefslogtreecommitdiffstats
path: root/scripts/lib/recipetool
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2016-09-19 08:08:06 +1200
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-09-20 15:11:07 +0100
commite30276cb185b5b4448628b39fbbd533abbb0f94e (patch)
tree1515436b7929cb5975bfb441d984b88b9ebd934c /scripts/lib/recipetool
parent9aa1cf3a28eab3420e15f14daba7cf3b8c484a6d (diff)
downloadpoky-e30276cb185b5b4448628b39fbbd533abbb0f94e.tar.gz
recipetool: create: fix name/version extraction from filename
I ran into an example where recipetool was getting the name/version completely wrong: https://bitbucket.org/sortsmill/libunicodenames/downloads/libunicodenames-1.1.0_beta1.tar.xz >From this it would create a libunicodenames-1.1.0-beta1_1.1.0-beta1.bb file (likely because it couldn't split the file name and therefore took all of it, then got the version from one of the files inside the tarball). When this happens it's just irritating because you then have to delete the recipe / run devtool reset and then run recipetool create / devtool add again and specify the version manually. This patch is the result of systematically running the determine_from_filename() function over the files on the Yocto Project source mirror and my local downloads directory and fixing as many of the generic issues as reasonably practical - it now gets the name and version correct much more often. There are still cases where it won't, but they are now in the minority. (From OE-Core rev: 7b018b1d493a8d10fd02b8cc220990b191c87fe5) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/recipetool')
-rw-r--r--scripts/lib/recipetool/create.py50
1 files changed, 36 insertions, 14 deletions
diff --git a/scripts/lib/recipetool/create.py b/scripts/lib/recipetool/create.py
index cd86747821..f7b0676f32 100644
--- a/scripts/lib/recipetool/create.py
+++ b/scripts/lib/recipetool/create.py
@@ -256,27 +256,49 @@ def validate_pv(pv):
256 256
257def determine_from_filename(srcfile): 257def determine_from_filename(srcfile):
258 """Determine name and version from a filename""" 258 """Determine name and version from a filename"""
259 part = ''
260 if '.tar.' in srcfile:
261 namepart = srcfile.split('.tar.')[0].lower()
262 else:
263 namepart = os.path.splitext(srcfile)[0].lower()
264 if is_package(srcfile): 259 if is_package(srcfile):
265 # Force getting the value from the package metadata 260 # Force getting the value from the package metadata
266 return None, None 261 return None, None
262
263 if '.tar.' in srcfile:
264 namepart = srcfile.split('.tar.')[0]
267 else: 265 else:
268 splitval = namepart.rsplit('_', 1) 266 namepart = os.path.splitext(srcfile)[0]
267 namepart = namepart.lower().replace('_', '-')
268 if namepart.endswith('.src'):
269 namepart = namepart[:-4]
270 if namepart.endswith('.orig'):
271 namepart = namepart[:-5]
272 splitval = namepart.split('-')
273 logger.debug('determine_from_filename: split name %s into: %s' % (srcfile, splitval))
274
275 ver_re = re.compile('^v?[0-9]')
276
277 pv = None
278 pn = None
269 if len(splitval) == 1: 279 if len(splitval) == 1:
270 splitval = namepart.rsplit('-', 1) 280 # Try to split the version out if there is no separator (or a .)
271 pn = splitval[0].replace('_', '-') 281 res = re.match('^([^0-9]+)([0-9.]+.*)$', namepart)
272 if len(splitval) > 1: 282 if res:
273 if splitval[1][0] in '0123456789': 283 if len(res.group(1)) > 1 and len(res.group(2)) > 1:
274 pv = splitval[1] 284 pn = res.group(1).rstrip('.')
285 pv = res.group(2)
275 else: 286 else:
276 pn = '-'.join(splitval).replace('_', '-') 287 pn = namepart
277 pv = None
278 else: 288 else:
279 pv = None 289 if splitval[-1] in ['source', 'src']:
290 splitval.pop()
291 if len(splitval) > 2 and re.match('^(alpha|beta|stable|release|rc[0-9]|pre[0-9]|p[0-9]|[0-9]{8})', splitval[-1]) and ver_re.match(splitval[-2]):
292 pv = '-'.join(splitval[-2:])
293 if pv.endswith('-release'):
294 pv = pv[:-8]
295 splitval = splitval[:-2]
296 elif ver_re.match(splitval[-1]):
297 pv = splitval.pop()
298 pn = '-'.join(splitval)
299 if pv and pv.startswith('v'):
300 pv = pv[1:]
301 logger.debug('determine_from_filename: name = "%s" version = "%s"' % (pn, pv))
280 return (pn, pv) 302 return (pn, pv)
281 303
282def determine_from_url(srcuri): 304def determine_from_url(srcuri):