diff options
Diffstat (limited to 'yocto-poky/scripts/lib/recipetool/create.py')
-rw-r--r-- | yocto-poky/scripts/lib/recipetool/create.py | 74 |
1 files changed, 65 insertions, 9 deletions
diff --git a/yocto-poky/scripts/lib/recipetool/create.py b/yocto-poky/scripts/lib/recipetool/create.py index c4754dbcd..8305e4364 100644 --- a/yocto-poky/scripts/lib/recipetool/create.py +++ b/yocto-poky/scripts/lib/recipetool/create.py @@ -23,6 +23,7 @@ import fnmatch import re import logging import scriptutils +import urlparse logger = logging.getLogger('recipetool') @@ -46,10 +47,26 @@ class RecipeHandler(): results.extend(glob.glob(os.path.join(path, spec))) return results - def genfunction(self, outlines, funcname, content): - outlines.append('%s () {' % funcname) + def genfunction(self, outlines, funcname, content, python=False, forcespace=False): + if python: + prefix = 'python ' + else: + prefix = '' + outlines.append('%s%s () {' % (prefix, funcname)) + if python or forcespace: + indent = ' ' + else: + indent = '\t' + addnoop = not python for line in content: - outlines.append('\t%s' % line) + outlines.append('%s%s' % (indent, line)) + if addnoop: + strippedline = line.lstrip() + if strippedline and not strippedline.startswith('#'): + addnoop = False + if addnoop: + # Without this there'll be a syntax error + outlines.append('%s:' % indent) outlines.append('}') outlines.append('') @@ -86,7 +103,17 @@ def create_recipe(args): srcrev = '${AUTOREV}' if '://' in args.source: # Fetch a URL - srcuri = args.source + fetchuri = 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) if res: @@ -95,14 +122,25 @@ def create_recipe(args): tempsrc = tempfile.mkdtemp(prefix='recipetool-') srctree = tempsrc logger.info('Fetching %s...' % srcuri) - checksums = scriptutils.fetch_uri(tinfoil.config_data, args.source, srctree, srcrev) + try: + checksums = scriptutils.fetch_uri(tinfoil.config_data, fetchuri, srctree, srcrev) + except bb.fetch2.FetchError: + # Error already printed + sys.exit(1) dirlist = os.listdir(srctree) if 'git.indirectionsymlink' in dirlist: dirlist.remove('git.indirectionsymlink') - if len(dirlist) == 1 and os.path.isdir(os.path.join(srctree, dirlist[0])): - # We unpacked a single directory, so we should use that - srcsubdir = dirlist[0] - srctree = os.path.join(srctree, srcsubdir) + if len(dirlist) == 1: + singleitem = os.path.join(srctree, dirlist[0]) + if os.path.isdir(singleitem): + # We unpacked a single directory, so we should use that + srcsubdir = dirlist[0] + srctree = os.path.join(srctree, srcsubdir) + else: + with open(singleitem, 'r') as f: + if '<html' in f.read(100).lower(): + logger.error('Fetching "%s" returned a single HTML page - check the URL is correct and functional' % fetchuri) + sys.exit(1) else: # Assume we're pointing to an existing source tree if args.extract_to: @@ -208,6 +246,10 @@ def create_recipe(args): lines_after.append('PACKAGE_ARCH = "%s"' % pkgarch) lines_after.append('') + if args.binary: + lines_after.append('INSANE_SKIP_${PN} += "already-stripped"') + lines_after.append('') + # Find all plugins that want to register handlers handlers = [] for plugin in plugins: @@ -217,6 +259,11 @@ def create_recipe(args): # Apply the handlers classes = [] handled = [] + + if args.binary: + classes.append('bin_package') + handled.append('buildsystem') + for handler in handlers: handler.process(srctree, classes, lines_before, lines_after, handled) @@ -229,7 +276,15 @@ def create_recipe(args): if args.extract_to: scriptutils.git_convert_standalone_clone(srctree) + if os.path.isdir(args.extract_to): + # If the directory exists we'll move the temp dir into it instead of + # its contents - of course, we could try to always move its contents + # but that is a pain if there are symlinks; the simplest solution is + # to just remove it first + os.rmdir(args.extract_to) shutil.move(srctree, args.extract_to) + if tempsrc == srctree: + tempsrc = None logger.info('Source extracted to %s' % args.extract_to) if outfile == '-': @@ -408,5 +463,6 @@ def register_command(subparsers): parser_create.add_argument('-m', '--machine', help='Make recipe machine-specific as opposed to architecture-specific', action='store_true') parser_create.add_argument('-x', '--extract-to', metavar='EXTRACTPATH', help='Assuming source is a URL, fetch it and extract it to the directory specified as %(metavar)s') parser_create.add_argument('-V', '--version', help='Version to use within recipe (PV)') + parser_create.add_argument('-b', '--binary', help='Treat the source tree as something that should be installed verbatim (no compilation, same directory structure)', action='store_true') parser_create.set_defaults(func=create_recipe) |