diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2016-01-23 00:59:59 +1300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-01-22 23:42:57 +0000 |
commit | b143d414846854dc8b3e0a47358daf5646eded38 (patch) | |
tree | 013a77e593920c3348281778dfca343319d1fc8d /scripts/lib | |
parent | 59682d78f95732e014f78f13e0a05f843860d9bb (diff) | |
download | openembedded-core-b143d414846854dc8b3e0a47358daf5646eded38.tar.gz openembedded-core-b143d414846854dc8b3e0a47358daf5646eded38.tar.bz2 openembedded-core-b143d414846854dc8b3e0a47358daf5646eded38.zip |
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.
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib')
-rw-r--r-- | scripts/lib/recipetool/create.py | 30 |
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): return True return False +def reformat_git_uri(uri): + '''Convert any http[s]://....git URI into git://...;protocol=http[s]''' + res = re.match('(https?)://([^;]+\.git)(;.*)?$', uri) + if res: + # Need to switch the URI around so that the git fetcher is used + return 'git://%s;protocol=%s%s' % (res.group(2), res.group(1), res.group(3) or '') + return uri + def create_recipe(args): import bb.process import tempfile @@ -275,16 +283,11 @@ def create_recipe(args): srcrev = '${AUTOREV}' if '://' in args.source: # Fetch a URL - fetchuri = urlparse.urldefrag(args.source)[0] + fetchuri = reformat_git_uri(urlparse.urldefrag(args.source)[0]) if args.binary: # Assume the archive contains the directory structure verbatim # so we need to extract to a subdirectory fetchuri += ';subdir=%s' % os.path.splitext(os.path.basename(urlparse.urlsplit(fetchuri).path))[0] - git_re = re.compile('(https?)://([^;]+\.git)(;.*)?$') - res = git_re.match(fetchuri) - if res: - # Need to switch the URI around so that the git fetcher is used - fetchuri = 'git://%s;protocol=%s%s' % (res.group(2), res.group(1), res.group(3) or '') srcuri = fetchuri rev_re = re.compile(';rev=([^;]+)') res = rev_re.search(srcuri) @@ -321,8 +324,21 @@ def create_recipe(args): if not os.path.isdir(args.source): logger.error('Invalid source directory %s' % args.source) sys.exit(1) - srcuri = '' srctree = args.source + srcuri = '' + if os.path.exists(os.path.join(srctree, '.git')): + # Try to get upstream repo location from origin remote + try: + stdout, _ = bb.process.run('git remote -v', cwd=srctree, shell=True) + except bb.process.ExecutionError as e: + stdout = None + if stdout: + for line in stdout.splitlines(): + splitline = line.split() + if len(splitline) > 1: + if splitline[0] == 'origin' and '://' in splitline[1]: + srcuri = reformat_git_uri(splitline[1]) + break if args.src_subdir: srcsubdir = os.path.join(srcsubdir, args.src_subdir) |