aboutsummaryrefslogtreecommitdiffstats
path: root/scripts/lib/recipetool/create.py
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2015-12-22 17:03:03 +1300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-12-28 09:25:13 +0000
commitebe5f0b872751fd11167a018f1ff7dc350da476e (patch)
tree5718f6e221834d0d90a802ffa9c34deee1dac4ee /scripts/lib/recipetool/create.py
parentdb5f9645ad3ffb4e9be7075d71cb1b13341f5195 (diff)
downloadopenembedded-core-contrib-ebe5f0b872751fd11167a018f1ff7dc350da476e.tar.gz
recipetool: create: basic extraction of name/version from filename
Often the filename (e.g. source tarball) contains the name and version of the software it contains. (This isn't intended to be exhaustive, just to catch the common case.) (From OE-Core rev: 944eacfb849ee69b41e12c9de4f264406281ac6a) 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/create.py')
-rw-r--r--scripts/lib/recipetool/create.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/scripts/lib/recipetool/create.py b/scripts/lib/recipetool/create.py
index 6c7b9fd7e8..4887604219 100644
--- a/scripts/lib/recipetool/create.py
+++ b/scripts/lib/recipetool/create.py
@@ -86,6 +86,27 @@ def validate_pv(pv):
return False
return True
+def determine_from_filename(srcfile):
+ """Determine name and version from a filename"""
+ part = ''
+ if '.tar.' in srcfile:
+ namepart = srcfile.split('.tar.')[0]
+ else:
+ namepart = os.path.splitext(srcfile)[0]
+ splitval = namepart.rsplit('_', 1)
+ if len(splitval) == 1:
+ splitval = namepart.rsplit('-', 1)
+ pn = splitval[0].replace('_', '-')
+ if len(splitval) > 1:
+ if splitval[1][0] in '0123456789':
+ pv = splitval[1]
+ else:
+ pn = '-'.join(splitval).replace('_', '-')
+ pv = None
+ else:
+ pv = None
+ return (pn, pv)
+
def supports_srcrev(uri):
localdata = bb.data.createCopy(tinfoil.config_data)
# This is a bit sad, but if you don't have this set there can be some
@@ -234,6 +255,17 @@ def create_recipe(args):
else:
realpv = None
+ if srcuri and not realpv or not pn:
+ parseres = urlparse.urlparse(srcuri)
+ if parseres.path:
+ srcfile = os.path.basename(parseres.path)
+ name_pn, name_pv = determine_from_filename(srcfile)
+ logger.debug('Determined from filename: name = "%s", version = "%s"' % (name_pn, name_pv))
+ if name_pn and not pn:
+ pn = name_pn
+ if name_pv and not realpv:
+ realpv = name_pv
+
if not srcuri:
lines_before.append('# No information for SRC_URI yet (only an external source tree was specified)')
lines_before.append('SRC_URI = "%s"' % srcuri)