summaryrefslogtreecommitdiffstats
path: root/scripts/lib/recipetool/create.py
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2016-01-23 00:59:59 +1300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-01-24 09:40:33 +0000
commitb307e0a604cf1a8224a7b17f78ea2acc19d98fe2 (patch)
tree8f4206b909d421960e303b5adb320bfb70874d65 /scripts/lib/recipetool/create.py
parent50e40fc91f74cce464dc5c7556550cfe91b95c7c (diff)
downloadpoky-b307e0a604cf1a8224a7b17f78ea2acc19d98fe2.tar.gz
recipetool: create: extract SRC_URI from local git repositories
If you specify a local directory which happens to be a git repository with an origin remote (and it is in fact remote), we can use that for SRC_URI rather than leaving it blank in the recipe. (From OE-Core rev: b143d414846854dc8b3e0a47358daf5646eded38) 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.py30
1 files changed, 23 insertions, 7 deletions
diff --git a/scripts/lib/recipetool/create.py b/scripts/lib/recipetool/create.py
index 9c3a63d155..5caf3741b8 100644
--- a/scripts/lib/recipetool/create.py
+++ b/scripts/lib/recipetool/create.py
@@ -260,6 +260,14 @@ def supports_srcrev(uri):
260 return True 260 return True
261 return False 261 return False
262 262
263def reformat_git_uri(uri):
264 '''Convert any http[s]://....git URI into git://...;protocol=http[s]'''
265 res = re.match('(https?)://([^;]+\.git)(;.*)?$', uri)
266 if res:
267 # Need to switch the URI around so that the git fetcher is used
268 return 'git://%s;protocol=%s%s' % (res.group(2), res.group(1), res.group(3) or '')
269 return uri
270
263def create_recipe(args): 271def create_recipe(args):
264 import bb.process 272 import bb.process
265 import tempfile 273 import tempfile
@@ -275,16 +283,11 @@ def create_recipe(args):
275 srcrev = '${AUTOREV}' 283 srcrev = '${AUTOREV}'
276 if '://' in args.source: 284 if '://' in args.source:
277 # Fetch a URL 285 # Fetch a URL
278 fetchuri = urlparse.urldefrag(args.source)[0] 286 fetchuri = reformat_git_uri(urlparse.urldefrag(args.source)[0])
279 if args.binary: 287 if args.binary:
280 # Assume the archive contains the directory structure verbatim 288 # Assume the archive contains the directory structure verbatim
281 # so we need to extract to a subdirectory 289 # so we need to extract to a subdirectory
282 fetchuri += ';subdir=%s' % os.path.splitext(os.path.basename(urlparse.urlsplit(fetchuri).path))[0] 290 fetchuri += ';subdir=%s' % os.path.splitext(os.path.basename(urlparse.urlsplit(fetchuri).path))[0]
283 git_re = re.compile('(https?)://([^;]+\.git)(;.*)?$')
284 res = git_re.match(fetchuri)
285 if res:
286 # Need to switch the URI around so that the git fetcher is used
287 fetchuri = 'git://%s;protocol=%s%s' % (res.group(2), res.group(1), res.group(3) or '')
288 srcuri = fetchuri 291 srcuri = fetchuri
289 rev_re = re.compile(';rev=([^;]+)') 292 rev_re = re.compile(';rev=([^;]+)')
290 res = rev_re.search(srcuri) 293 res = rev_re.search(srcuri)
@@ -321,8 +324,21 @@ def create_recipe(args):
321 if not os.path.isdir(args.source): 324 if not os.path.isdir(args.source):
322 logger.error('Invalid source directory %s' % args.source) 325 logger.error('Invalid source directory %s' % args.source)
323 sys.exit(1) 326 sys.exit(1)
324 srcuri = ''
325 srctree = args.source 327 srctree = args.source
328 srcuri = ''
329 if os.path.exists(os.path.join(srctree, '.git')):
330 # Try to get upstream repo location from origin remote
331 try:
332 stdout, _ = bb.process.run('git remote -v', cwd=srctree, shell=True)
333 except bb.process.ExecutionError as e:
334 stdout = None
335 if stdout:
336 for line in stdout.splitlines():
337 splitline = line.split()
338 if len(splitline) > 1:
339 if splitline[0] == 'origin' and '://' in splitline[1]:
340 srcuri = reformat_git_uri(splitline[1])
341 break
326 342
327 if args.src_subdir: 343 if args.src_subdir:
328 srcsubdir = os.path.join(srcsubdir, args.src_subdir) 344 srcsubdir = os.path.join(srcsubdir, args.src_subdir)