]> code.ossystems Code Review - openembedded-core.git/commitdiff
recipetool: create: support git short form URLs
authorPaul Eggleton <paul.eggleton@linux.intel.com>
Sun, 18 Sep 2016 20:08:11 +0000 (08:08 +1200)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 19 Sep 2016 08:06:52 +0000 (09:06 +0100)
In keeping with making recipetool create / devtool add as easy to use as
possible, users shouldn't have to know how to reformat git short form ssh
URLs for consumption by BitBake's fetcher (for example
user@git.example.com:repo.git should be expressed as
git://user@git.example.com/repo.git;protocol=ssh ) - instead we should
just take care of that automatically. Add some logic in the appropriate
places to do that.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
scripts/lib/devtool/standard.py
scripts/lib/recipetool/create.py
scripts/lib/scriptutils.py

index baef23e46770ddc0caa25b3df9016e02a9c04c0d..abbc0cb8f51e6341a2f8f6e385d5cdf46e29c3e3 100644 (file)
@@ -47,13 +47,13 @@ def add(args, config, basepath, workspace):
     # These are positional arguments, but because we're nice, allow
     # specifying e.g. source tree without name, or fetch URI without name or
     # source tree (if we can detect that that is what the user meant)
-    if '://' in args.recipename:
+    if scriptutils.is_src_url(args.recipename):
         if not args.fetchuri:
             if args.fetch:
                 raise DevtoolError('URI specified as positional argument as well as -f/--fetch')
             args.fetchuri = args.recipename
             args.recipename = ''
-    elif args.srctree and '://' in args.srctree:
+    elif scriptutils.is_src_url(args.srctree):
         if not args.fetchuri:
             if args.fetch:
                 raise DevtoolError('URI specified as positional argument as well as -f/--fetch')
index 7787d8e35f404c60e79f4c3725650123078950de..9b31fe92d7d459adde3cd1811782ab20d4bc8ba4 100644 (file)
@@ -353,10 +353,13 @@ def reformat_git_uri(uri):
     '''Convert any http[s]://....git URI into git://...;protocol=http[s]'''
     checkuri = uri.split(';', 1)[0]
     if checkuri.endswith('.git') or '/git/' in checkuri or re.match('https?://github.com/[^/]+/[^/]+/?$', checkuri):
-        res = re.match('(https?)://([^;]+(\.git)?)(;.*)?$', uri)
+        res = re.match('(http|https|ssh)://([^;]+(\.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(4) or '')
+        elif '@' in checkuri:
+            # Catch e.g. git@git.example.com:repo.git
+            return 'git://%s;protocol=ssh' % checkuri.replace(':', '/', 1)
     return uri
 
 def is_package(url):
@@ -386,7 +389,7 @@ def create_recipe(args):
     if os.path.isfile(source):
         source = 'file://%s' % os.path.abspath(source)
 
-    if '://' in source:
+    if scriptutils.is_src_url(source):
         # Fetch a URL
         fetchuri = reformat_git_uri(urldefrag(source)[0])
         if args.binary:
@@ -478,7 +481,7 @@ def create_recipe(args):
                 for line in stdout.splitlines():
                     splitline = line.split()
                     if len(splitline) > 1:
-                        if splitline[0] == 'origin' and '://' in splitline[1]:
+                        if splitline[0] == 'origin' and scriptutils.is_src_url(splitline[1]):
                             srcuri = reformat_git_uri(splitline[1])
                             srcsubdir = 'git'
                             break
index bd082d8581a62c3fa49689ded752c99f84575b5d..5ccc0279685e78ce364e4c24630fc896ad79a976 100644 (file)
@@ -116,3 +116,16 @@ def run_editor(fn):
     except OSError as exc:
         logger.error("Execution of editor '%s' failed: %s", editor, exc)
         return 1
+
+def is_src_url(param):
+    """
+    Check if a parameter is a URL and return True if so
+    NOTE: be careful about changing this as it will influence how devtool/recipetool command line handling works
+    """
+    if not param:
+        return False
+    elif '://' in param:
+        return True
+    elif param.startswith('git@') or ('@' in param and param.endswith('.git')):
+        return True
+    return False