diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2016-09-19 08:08:11 +1200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-09-20 15:11:07 +0100 |
commit | 90f925cd41a372c839289b25f1f55490c77f4dd7 (patch) | |
tree | e2b613f51eb508af0714d101e1a5c261d8018d50 /scripts | |
parent | 147774fc1ca9d1fd1afd5e2f255dccbfe464dabd (diff) | |
download | poky-90f925cd41a372c839289b25f1f55490c77f4dd7.tar.gz |
recipetool: create: support git short form URLs
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.
(From OE-Core rev: 78c672a72f49c4b6cfd8c247efcc676b0ba1681a)
Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/devtool/standard.py | 4 | ||||
-rw-r--r-- | scripts/lib/recipetool/create.py | 9 | ||||
-rw-r--r-- | scripts/lib/scriptutils.py | 13 |
3 files changed, 21 insertions, 5 deletions
diff --git a/scripts/lib/devtool/standard.py b/scripts/lib/devtool/standard.py index baef23e467..abbc0cb8f5 100644 --- a/scripts/lib/devtool/standard.py +++ b/scripts/lib/devtool/standard.py | |||
@@ -47,13 +47,13 @@ def add(args, config, basepath, workspace): | |||
47 | # These are positional arguments, but because we're nice, allow | 47 | # These are positional arguments, but because we're nice, allow |
48 | # specifying e.g. source tree without name, or fetch URI without name or | 48 | # specifying e.g. source tree without name, or fetch URI without name or |
49 | # source tree (if we can detect that that is what the user meant) | 49 | # source tree (if we can detect that that is what the user meant) |
50 | if '://' in args.recipename: | 50 | if scriptutils.is_src_url(args.recipename): |
51 | if not args.fetchuri: | 51 | if not args.fetchuri: |
52 | if args.fetch: | 52 | if args.fetch: |
53 | raise DevtoolError('URI specified as positional argument as well as -f/--fetch') | 53 | raise DevtoolError('URI specified as positional argument as well as -f/--fetch') |
54 | args.fetchuri = args.recipename | 54 | args.fetchuri = args.recipename |
55 | args.recipename = '' | 55 | args.recipename = '' |
56 | elif args.srctree and '://' in args.srctree: | 56 | elif scriptutils.is_src_url(args.srctree): |
57 | if not args.fetchuri: | 57 | if not args.fetchuri: |
58 | if args.fetch: | 58 | if args.fetch: |
59 | raise DevtoolError('URI specified as positional argument as well as -f/--fetch') | 59 | raise DevtoolError('URI specified as positional argument as well as -f/--fetch') |
diff --git a/scripts/lib/recipetool/create.py b/scripts/lib/recipetool/create.py index 7787d8e35f..9b31fe92d7 100644 --- a/scripts/lib/recipetool/create.py +++ b/scripts/lib/recipetool/create.py | |||
@@ -353,10 +353,13 @@ def reformat_git_uri(uri): | |||
353 | '''Convert any http[s]://....git URI into git://...;protocol=http[s]''' | 353 | '''Convert any http[s]://....git URI into git://...;protocol=http[s]''' |
354 | checkuri = uri.split(';', 1)[0] | 354 | checkuri = uri.split(';', 1)[0] |
355 | if checkuri.endswith('.git') or '/git/' in checkuri or re.match('https?://github.com/[^/]+/[^/]+/?$', checkuri): | 355 | if checkuri.endswith('.git') or '/git/' in checkuri or re.match('https?://github.com/[^/]+/[^/]+/?$', checkuri): |
356 | res = re.match('(https?)://([^;]+(\.git)?)(;.*)?$', uri) | 356 | res = re.match('(http|https|ssh)://([^;]+(\.git)?)(;.*)?$', uri) |
357 | if res: | 357 | if res: |
358 | # Need to switch the URI around so that the git fetcher is used | 358 | # Need to switch the URI around so that the git fetcher is used |
359 | return 'git://%s;protocol=%s%s' % (res.group(2), res.group(1), res.group(4) or '') | 359 | return 'git://%s;protocol=%s%s' % (res.group(2), res.group(1), res.group(4) or '') |
360 | elif '@' in checkuri: | ||
361 | # Catch e.g. git@git.example.com:repo.git | ||
362 | return 'git://%s;protocol=ssh' % checkuri.replace(':', '/', 1) | ||
360 | return uri | 363 | return uri |
361 | 364 | ||
362 | def is_package(url): | 365 | def is_package(url): |
@@ -386,7 +389,7 @@ def create_recipe(args): | |||
386 | if os.path.isfile(source): | 389 | if os.path.isfile(source): |
387 | source = 'file://%s' % os.path.abspath(source) | 390 | source = 'file://%s' % os.path.abspath(source) |
388 | 391 | ||
389 | if '://' in source: | 392 | if scriptutils.is_src_url(source): |
390 | # Fetch a URL | 393 | # Fetch a URL |
391 | fetchuri = reformat_git_uri(urldefrag(source)[0]) | 394 | fetchuri = reformat_git_uri(urldefrag(source)[0]) |
392 | if args.binary: | 395 | if args.binary: |
@@ -478,7 +481,7 @@ def create_recipe(args): | |||
478 | for line in stdout.splitlines(): | 481 | for line in stdout.splitlines(): |
479 | splitline = line.split() | 482 | splitline = line.split() |
480 | if len(splitline) > 1: | 483 | if len(splitline) > 1: |
481 | if splitline[0] == 'origin' and '://' in splitline[1]: | 484 | if splitline[0] == 'origin' and scriptutils.is_src_url(splitline[1]): |
482 | srcuri = reformat_git_uri(splitline[1]) | 485 | srcuri = reformat_git_uri(splitline[1]) |
483 | srcsubdir = 'git' | 486 | srcsubdir = 'git' |
484 | break | 487 | break |
diff --git a/scripts/lib/scriptutils.py b/scripts/lib/scriptutils.py index bd082d8581..5ccc027968 100644 --- a/scripts/lib/scriptutils.py +++ b/scripts/lib/scriptutils.py | |||
@@ -116,3 +116,16 @@ def run_editor(fn): | |||
116 | except OSError as exc: | 116 | except OSError as exc: |
117 | logger.error("Execution of editor '%s' failed: %s", editor, exc) | 117 | logger.error("Execution of editor '%s' failed: %s", editor, exc) |
118 | return 1 | 118 | return 1 |
119 | |||
120 | def is_src_url(param): | ||
121 | """ | ||
122 | Check if a parameter is a URL and return True if so | ||
123 | NOTE: be careful about changing this as it will influence how devtool/recipetool command line handling works | ||
124 | """ | ||
125 | if not param: | ||
126 | return False | ||
127 | elif '://' in param: | ||
128 | return True | ||
129 | elif param.startswith('git@') or ('@' in param and param.endswith('.git')): | ||
130 | return True | ||
131 | return False | ||