diff options
Diffstat (limited to 'scripts/lib/recipetool/create_buildsys.py')
| -rw-r--r-- | scripts/lib/recipetool/create_buildsys.py | 142 |
1 files changed, 98 insertions, 44 deletions
diff --git a/scripts/lib/recipetool/create_buildsys.py b/scripts/lib/recipetool/create_buildsys.py index 43dcca3c5b..e914e53aab 100644 --- a/scripts/lib/recipetool/create_buildsys.py +++ b/scripts/lib/recipetool/create_buildsys.py @@ -1,6 +1,6 @@ # Recipe creation tool - create command build system handlers # -# Copyright (C) 2014 Intel Corporation +# Copyright (C) 2014-2016 Intel Corporation # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License version 2 as @@ -44,7 +44,7 @@ class CmakeRecipeHandler(RecipeHandler): classes.append('cmake') values = CmakeRecipeHandler.extract_cmake_deps(lines_before, srctree, extravalues) classes.extend(values.pop('inherit', '').split()) - for var, value in values.iteritems(): + for var, value in values.items(): lines_before.append('%s = "%s"' % (var, value)) lines_after.append('# Specify any options you want to pass to cmake using EXTRA_OECMAKE:') lines_after.append('EXTRA_OECMAKE = ""') @@ -159,7 +159,7 @@ class CmakeRecipeHandler(RecipeHandler): def find_cmake_package(pkg): RecipeHandler.load_devel_filemap(tinfoil.config_data) - for fn, pn in RecipeHandler.recipecmakefilemap.iteritems(): + for fn, pn in RecipeHandler.recipecmakefilemap.items(): splitname = fn.split('/') if len(splitname) > 1: if splitname[0].lower().startswith(pkg.lower()): @@ -173,7 +173,7 @@ class CmakeRecipeHandler(RecipeHandler): def parse_cmake_file(fn, paths=None): searchpaths = (paths or []) + [os.path.dirname(fn)] logger.debug('Parsing file %s' % fn) - with open(fn, 'r') as f: + with open(fn, 'r', errors='surrogateescape') as f: for line in f: line = line.strip() for handler in handlers: @@ -348,13 +348,13 @@ class AutotoolsRecipeHandler(RecipeHandler): autoconf = True values = AutotoolsRecipeHandler.extract_autotools_deps(lines_before, srctree, extravalues) classes.extend(values.pop('inherit', '').split()) - for var, value in values.iteritems(): + for var, value in values.items(): lines_before.append('%s = "%s"' % (var, value)) else: conffile = RecipeHandler.checkfiles(srctree, ['configure']) if conffile: # Check if this is just a pre-generated autoconf configure script - with open(conffile[0], 'r') as f: + with open(conffile[0], 'r', errors='surrogateescape') as f: for i in range(1, 10): if 'Generated by GNU Autoconf' in f.readline(): autoconf = True @@ -364,7 +364,7 @@ class AutotoolsRecipeHandler(RecipeHandler): # Last resort conffile = RecipeHandler.checkfiles(srctree, ['configure']) if conffile: - with open(conffile[0], 'r') as f: + with open(conffile[0], 'r', errors='surrogateescape') as f: for line in f: line = line.strip() if line.startswith('VERSION=') or line.startswith('PACKAGE_VERSION='): @@ -404,29 +404,50 @@ class AutotoolsRecipeHandler(RecipeHandler): values = {} inherits = [] - # FIXME this mapping is very thin + # Hardcoded map, we also use a dynamic one based on what's in the sysroot progmap = {'flex': 'flex-native', 'bison': 'bison-native', 'm4': 'm4-native', 'tar': 'tar-native', - 'ar': 'binutils-native'} + 'ar': 'binutils-native', + 'ranlib': 'binutils-native', + 'ld': 'binutils-native', + 'strip': 'binutils-native', + 'libtool': '', + 'autoconf': '', + 'autoheader': '', + 'automake': '', + 'uname': '', + 'rm': '', + 'cp': '', + 'mv': '', + 'find': '', + 'awk': '', + 'sed': '', + } progclassmap = {'gconftool-2': 'gconf', - 'pkg-config': 'pkgconfig'} - - pkg_re = re.compile('PKG_CHECK_MODULES\(\[?[a-zA-Z0-9_]*\]?, *\[?([^,\]]*)\]?[),].*') - pkgce_re = re.compile('PKG_CHECK_EXISTS\(\[?([^,\]]*)\]?[),].*') - lib_re = re.compile('AC_CHECK_LIB\(\[?([^,\]]*)\]?,.*') - libx_re = re.compile('AX_CHECK_LIBRARY\(\[?[^,\]]*\]?, *\[?([^,\]]*)\]?, *\[?([a-zA-Z0-9-]*)\]?,.*') - progs_re = re.compile('_PROGS?\(\[?[a-zA-Z0-9_]*\]?, \[?([^,\]]*)\]?[),].*') + 'pkg-config': 'pkgconfig', + 'python': 'pythonnative', + 'python3': 'python3native', + 'perl': 'perlnative', + 'makeinfo': 'texinfo', + } + + pkg_re = re.compile('PKG_CHECK_MODULES\(\s*\[?[a-zA-Z0-9_]*\]?,\s*\[?([^,\]]*)\]?[),].*') + pkgce_re = re.compile('PKG_CHECK_EXISTS\(\s*\[?([^,\]]*)\]?[),].*') + lib_re = re.compile('AC_CHECK_LIB\(\s*\[?([^,\]]*)\]?,.*') + libx_re = re.compile('AX_CHECK_LIBRARY\(\s*\[?[^,\]]*\]?,\s*\[?([^,\]]*)\]?,\s*\[?([a-zA-Z0-9-]*)\]?,.*') + progs_re = re.compile('_PROGS?\(\s*\[?[a-zA-Z0-9_]*\]?,\s*\[?([^,\]]*)\]?[),].*') dep_re = re.compile('([^ ><=]+)( [<>=]+ [^ ><=]+)?') - ac_init_re = re.compile('AC_INIT\(([^,]+), *([^,]+)[,)].*') - am_init_re = re.compile('AM_INIT_AUTOMAKE\(([^,]+), *([^,]+)[,)].*') - define_re = re.compile(' *(m4_)?define\(([^,]+), *([^,]+)\)') + ac_init_re = re.compile('AC_INIT\(\s*([^,]+),\s*([^,]+)[,)].*') + am_init_re = re.compile('AM_INIT_AUTOMAKE\(\s*([^,]+),\s*([^,]+)[,)].*') + define_re = re.compile('\s*(m4_)?define\(\s*([^,]+),\s*([^,]+)\)') + version_re = re.compile('([0-9.]+)') defines = {} def subst_defines(value): newvalue = value - for define, defval in defines.iteritems(): + for define, defval in defines.items(): newvalue = newvalue.replace(define, defval) if newvalue != value: return subst_defines(newvalue) @@ -462,10 +483,13 @@ class AutotoolsRecipeHandler(RecipeHandler): deps = [] unmapped = [] + RecipeHandler.load_binmap(tinfoil.config_data) + def process_macro(keyword, value): for handler in handlers: if handler.process_macro(srctree, keyword, value, process_value, libdeps, pcdeps, deps, outlines, inherits, values): return + logger.debug('Found keyword %s with value "%s"' % (keyword, value)) if keyword == 'PKG_CHECK_MODULES': res = pkg_re.search(value) if res: @@ -498,10 +522,12 @@ class AutotoolsRecipeHandler(RecipeHandler): if progclass: inherits.append(progclass) else: - progdep = progmap.get(prog, None) + progdep = RecipeHandler.recipebinmap.get(prog, None) + if not progdep: + progdep = progmap.get(prog, None) if progdep: deps.append(progdep) - else: + elif progdep is None: if not prog.startswith('$'): unmapped.append(prog) elif keyword == 'AC_CHECK_LIB': @@ -516,7 +542,7 @@ class AutotoolsRecipeHandler(RecipeHandler): lib = res.group(2) if not lib.startswith('$'): header = res.group(1) - libdeps.add((lib, header)) + libdeps.append((lib, header)) elif keyword == 'AC_PATH_X': deps.append('libx11') elif keyword in ('AX_BOOST', 'BOOST_REQUIRE'): @@ -545,10 +571,21 @@ class AutotoolsRecipeHandler(RecipeHandler): deps.append('sqlite3') elif keyword == 'AX_LIB_TAGLIB': deps.append('taglib') - elif keyword == 'AX_PKG_SWIG': - deps.append('swig') + elif keyword in ['AX_PKG_SWIG', 'AC_PROG_SWIG']: + deps.append('swig-native') elif keyword == 'AX_PROG_XSLTPROC': deps.append('libxslt-native') + elif keyword in ['AC_PYTHON_DEVEL', 'AX_PYTHON_DEVEL', 'AM_PATH_PYTHON']: + pythonclass = 'pythonnative' + res = version_re.search(value) + if res: + if res.group(1).startswith('3'): + pythonclass = 'python3native' + # Avoid replacing python3native with pythonnative + if not pythonclass in inherits and not 'python3native' in inherits: + if 'pythonnative' in inherits: + inherits.remove('pythonnative') + inherits.append(pythonclass) elif keyword == 'AX_WITH_CURSES': deps.append('ncurses') elif keyword == 'AX_PATH_BDB': @@ -614,7 +651,11 @@ class AutotoolsRecipeHandler(RecipeHandler): 'AX_LIB_SQLITE3', 'AX_LIB_TAGLIB', 'AX_PKG_SWIG', + 'AC_PROG_SWIG', 'AX_PROG_XSLTPROC', + 'AC_PYTHON_DEVEL', + 'AX_PYTHON_DEVEL', + 'AM_PATH_PYTHON', 'AX_WITH_CURSES', 'AX_PATH_BDB', 'AX_PATH_LIB_PCRE', @@ -630,7 +671,7 @@ class AutotoolsRecipeHandler(RecipeHandler): nesting = 0 in_keyword = '' partial = '' - with open(srcfile, 'r') as f: + with open(srcfile, 'r', errors='surrogateescape') as f: for line in f: if in_keyword: partial += ' ' + line.strip() @@ -658,7 +699,7 @@ class AutotoolsRecipeHandler(RecipeHandler): process_macro(in_keyword, partial) if extravalues: - for k,v in extravalues.items(): + for k,v in list(extravalues.items()): if v: if v.startswith('$') or v.startswith('@') or v.startswith('%'): del extravalues[k] @@ -713,7 +754,7 @@ class MakefileRecipeHandler(RecipeHandler): if 'buildsystem' in handled: return False - makefile = RecipeHandler.checkfiles(srctree, ['Makefile']) + makefile = RecipeHandler.checkfiles(srctree, ['Makefile', 'makefile', 'GNUmakefile']) if makefile: lines_after.append('# NOTE: this is a Makefile-only piece of software, so we cannot generate much of the') lines_after.append('# recipe automatically - you will need to examine the Makefile yourself and ensure') @@ -729,7 +770,7 @@ class MakefileRecipeHandler(RecipeHandler): if scanfile and os.path.exists(scanfile): values = AutotoolsRecipeHandler.extract_autotools_deps(lines_before, srctree, acfile=scanfile) classes.extend(values.pop('inherit', '').split()) - for var, value in values.iteritems(): + for var, value in values.items(): if var == 'DEPENDS': lines_before.append('# NOTE: some of these dependencies may be optional, check the Makefile and/or upstream documentation') lines_before.append('%s = "%s"' % (var, value)) @@ -756,7 +797,7 @@ class MakefileRecipeHandler(RecipeHandler): if installtarget: func.append('# This is a guess; additional arguments may be required') makeargs = '' - with open(makefile[0], 'r') as f: + with open(makefile[0], 'r', errors='surrogateescape') as f: for i in range(1, 100): if 'DESTDIR' in f.readline(): makeargs += " 'DESTDIR=${D}'" @@ -785,7 +826,7 @@ class VersionFileRecipeHandler(RecipeHandler): version = None for fileitem in filelist: linecount = 0 - with open(fileitem, 'r') as f: + with open(fileitem, 'r', errors='surrogateescape') as f: for line in f: line = line.rstrip().strip('"\'') linecount += 1 @@ -806,22 +847,35 @@ class SpecFileRecipeHandler(RecipeHandler): if 'PV' in extravalues and 'PN' in extravalues: return filelist = RecipeHandler.checkfiles(srctree, ['*.spec'], recursive=True) - pn = None - pv = None + valuemap = {'Name': 'PN', + 'Version': 'PV', + 'Summary': 'SUMMARY', + 'Url': 'HOMEPAGE', + 'License': 'LICENSE'} + foundvalues = {} for fileitem in filelist: linecount = 0 - with open(fileitem, 'r') as f: + with open(fileitem, 'r', errors='surrogateescape') as f: for line in f: - if line.startswith('Name:') and not pn: - pn = line.split(':')[1].strip() - if line.startswith('Version:') and not pv: - pv = line.split(':')[1].strip() - if pv or pn: - if pv and not 'PV' in extravalues and validate_pv(pv): - extravalues['PV'] = pv - if pn and not 'PN' in extravalues: - extravalues['PN'] = pn - break + for value, varname in valuemap.items(): + if line.startswith(value + ':') and not varname in foundvalues: + foundvalues[varname] = line.split(':', 1)[1].strip() + break + if len(foundvalues) == len(valuemap): + break + if 'PV' in foundvalues: + if not validate_pv(foundvalues['PV']): + del foundvalues['PV'] + license = foundvalues.pop('LICENSE', None) + if license: + liccomment = '# NOTE: spec file indicates the license may be "%s"' % license + for i, line in enumerate(lines_before): + if line.startswith('LICENSE ='): + lines_before.insert(i, liccomment) + break + else: + lines_before.append(liccomment) + extravalues.update(foundvalues) def register_recipe_handlers(handlers): # Set priorities with some gaps so that other plugins can insert |
