summaryrefslogtreecommitdiffstats
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
parentdb5f9645ad3ffb4e9be7075d71cb1b13341f5195 (diff)
downloadpoky-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>
-rw-r--r--meta/lib/oeqa/selftest/devtool.py15
-rw-r--r--scripts/lib/recipetool/create.py32
2 files changed, 40 insertions, 7 deletions
diff --git a/meta/lib/oeqa/selftest/devtool.py b/meta/lib/oeqa/selftest/devtool.py
index 8faea93784..7af82df632 100644
--- a/meta/lib/oeqa/selftest/devtool.py
+++ b/meta/lib/oeqa/selftest/devtool.py
@@ -232,15 +232,16 @@ class DevtoolTests(DevtoolBase):
232 self.assertIn(srcdir, result.output) 232 self.assertIn(srcdir, result.output)
233 # Check recipe 233 # Check recipe
234 recipefile = get_bb_var('FILE', testrecipe) 234 recipefile = get_bb_var('FILE', testrecipe)
235 self.assertIn('%s.bb' % testrecipe, recipefile, 'Recipe file incorrectly named') 235 self.assertIn('%s_%s.bb' % (testrecipe, testver), recipefile, 'Recipe file incorrectly named')
236 checkvars = {} 236 checkvars = {}
237 checkvars['S'] = '${WORKDIR}/MarkupSafe-%s' % testver 237 checkvars['S'] = '${WORKDIR}/MarkupSafe-${PV}'
238 checkvars['SRC_URI'] = url 238 checkvars['SRC_URI'] = url.replace(testver, '${PV}')
239 self._test_recipe_contents(recipefile, checkvars, []) 239 self._test_recipe_contents(recipefile, checkvars, [])
240 # Try with version specified 240 # Try with version specified
241 result = runCmd('devtool reset -n %s' % testrecipe) 241 result = runCmd('devtool reset -n %s' % testrecipe)
242 shutil.rmtree(srcdir) 242 shutil.rmtree(srcdir)
243 result = runCmd('devtool add %s %s -f %s -V %s' % (testrecipe, srcdir, url, testver)) 243 fakever = '1.9'
244 result = runCmd('devtool add %s %s -f %s -V %s' % (testrecipe, srcdir, url, fakever))
244 self.assertTrue(os.path.isfile(os.path.join(srcdir, 'setup.py')), 'Unable to find setup.py in source directory') 245 self.assertTrue(os.path.isfile(os.path.join(srcdir, 'setup.py')), 'Unable to find setup.py in source directory')
245 # Test devtool status 246 # Test devtool status
246 result = runCmd('devtool status') 247 result = runCmd('devtool status')
@@ -248,10 +249,10 @@ class DevtoolTests(DevtoolBase):
248 self.assertIn(srcdir, result.output) 249 self.assertIn(srcdir, result.output)
249 # Check recipe 250 # Check recipe
250 recipefile = get_bb_var('FILE', testrecipe) 251 recipefile = get_bb_var('FILE', testrecipe)
251 self.assertIn('%s_%s.bb' % (testrecipe, testver), recipefile, 'Recipe file incorrectly named') 252 self.assertIn('%s_%s.bb' % (testrecipe, fakever), recipefile, 'Recipe file incorrectly named')
252 checkvars = {} 253 checkvars = {}
253 checkvars['S'] = '${WORKDIR}/MarkupSafe-${PV}' 254 checkvars['S'] = '${WORKDIR}/MarkupSafe-%s' % testver
254 checkvars['SRC_URI'] = url.replace(testver, '${PV}') 255 checkvars['SRC_URI'] = url
255 self._test_recipe_contents(recipefile, checkvars, []) 256 self._test_recipe_contents(recipefile, checkvars, [])
256 257
257 @testcase(1161) 258 @testcase(1161)
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):
86 return False 86 return False
87 return True 87 return True
88 88
89def determine_from_filename(srcfile):
90 """Determine name and version from a filename"""
91 part = ''
92 if '.tar.' in srcfile:
93 namepart = srcfile.split('.tar.')[0]
94 else:
95 namepart = os.path.splitext(srcfile)[0]
96 splitval = namepart.rsplit('_', 1)
97 if len(splitval) == 1:
98 splitval = namepart.rsplit('-', 1)
99 pn = splitval[0].replace('_', '-')
100 if len(splitval) > 1:
101 if splitval[1][0] in '0123456789':
102 pv = splitval[1]
103 else:
104 pn = '-'.join(splitval).replace('_', '-')
105 pv = None
106 else:
107 pv = None
108 return (pn, pv)
109
89def supports_srcrev(uri): 110def supports_srcrev(uri):
90 localdata = bb.data.createCopy(tinfoil.config_data) 111 localdata = bb.data.createCopy(tinfoil.config_data)
91 # This is a bit sad, but if you don't have this set there can be some 112 # 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):
234 else: 255 else:
235 realpv = None 256 realpv = None
236 257
258 if srcuri and not realpv or not pn:
259 parseres = urlparse.urlparse(srcuri)
260 if parseres.path:
261 srcfile = os.path.basename(parseres.path)
262 name_pn, name_pv = determine_from_filename(srcfile)
263 logger.debug('Determined from filename: name = "%s", version = "%s"' % (name_pn, name_pv))
264 if name_pn and not pn:
265 pn = name_pn
266 if name_pv and not realpv:
267 realpv = name_pv
268
237 if not srcuri: 269 if not srcuri:
238 lines_before.append('# No information for SRC_URI yet (only an external source tree was specified)') 270 lines_before.append('# No information for SRC_URI yet (only an external source tree was specified)')
239 lines_before.append('SRC_URI = "%s"' % srcuri) 271 lines_before.append('SRC_URI = "%s"' % srcuri)