diff options
Diffstat (limited to 'import-layers/yocto-poky/scripts/lib/recipetool/create_buildsys_python.py')
-rw-r--r-- | import-layers/yocto-poky/scripts/lib/recipetool/create_buildsys_python.py | 100 |
1 files changed, 49 insertions, 51 deletions
diff --git a/import-layers/yocto-poky/scripts/lib/recipetool/create_buildsys_python.py b/import-layers/yocto-poky/scripts/lib/recipetool/create_buildsys_python.py index c3823307a..e41d81a31 100644 --- a/import-layers/yocto-poky/scripts/lib/recipetool/create_buildsys_python.py +++ b/import-layers/yocto-poky/scripts/lib/recipetool/create_buildsys_python.py @@ -61,8 +61,6 @@ class PythonRecipeHandler(RecipeHandler): } # PN/PV are already set by recipetool core & desc can be extremely long excluded_fields = [ - 'Name', - 'Version', 'Description', ] setup_parse_map = { @@ -88,8 +86,11 @@ class PythonRecipeHandler(RecipeHandler): ] setuparg_multi_line_values = ['Description'] replacements = [ + ('License', r' +$', ''), + ('License', r'^ +', ''), ('License', r' ', '-'), - ('License', r'-License$', ''), + ('License', r'^GNU-', ''), + ('License', r'-[Ll]icen[cs]e(,?-[Vv]ersion)?', ''), ('License', r'^UNKNOWN$', ''), # Remove currently unhandled version numbers from these variables @@ -218,6 +219,9 @@ class PythonRecipeHandler(RecipeHandler): else: info = self.get_setup_args_info(setupscript) + # Grab the license value before applying replacements + license_str = info.get('License', '').strip() + self.apply_info_replacements(info) if uses_setuptools: @@ -225,63 +229,53 @@ class PythonRecipeHandler(RecipeHandler): else: classes.append('distutils') + if license_str: + for i, line in enumerate(lines_before): + if line.startswith('LICENSE = '): + lines_before.insert(i, '# NOTE: License in setup.py/PKGINFO is: %s' % license_str) + break + if 'Classifier' in info: + existing_licenses = info.get('License', '') licenses = [] for classifier in info['Classifier']: if classifier in self.classifier_license_map: license = self.classifier_license_map[classifier] + if license == 'Apache' and 'Apache-2.0' in existing_licenses: + license = 'Apache-2.0' + elif license == 'GPL': + if 'GPL-2.0' in existing_licenses or 'GPLv2' in existing_licenses: + license = 'GPL-2.0' + elif 'GPL-3.0' in existing_licenses or 'GPLv3' in existing_licenses: + license = 'GPL-3.0' + elif license == 'LGPL': + if 'LGPL-2.1' in existing_licenses or 'LGPLv2.1' in existing_licenses: + license = 'LGPL-2.1' + elif 'LGPL-2.0' in existing_licenses or 'LGPLv2' in existing_licenses: + license = 'LGPL-2.0' + elif 'LGPL-3.0' in existing_licenses or 'LGPLv3' in existing_licenses: + license = 'LGPL-3.0' licenses.append(license) if licenses: info['License'] = ' & '.join(licenses) - # Map PKG-INFO & setup.py fields to bitbake variables - bbinfo = {} - for field, values in info.iteritems(): + for field, values in info.items(): if field in self.excluded_fields: continue if field not in self.bbvar_map: continue - if isinstance(values, basestring): + if isinstance(values, str): value = values else: value = ' '.join(str(v) for v in values if v) bbvar = self.bbvar_map[field] - if bbvar not in bbinfo and value: - bbinfo[bbvar] = value - - comment_lic_line = None - for pos, line in enumerate(list(lines_before)): - if line.startswith('#') and 'LICENSE' in line: - comment_lic_line = pos - elif line.startswith('LICENSE =') and 'LICENSE' in bbinfo: - if line in ('LICENSE = "Unknown"', 'LICENSE = "CLOSED"'): - lines_before[pos] = 'LICENSE = "{}"'.format(bbinfo['LICENSE']) - if line == 'LICENSE = "CLOSED"' and comment_lic_line: - lines_before[comment_lic_line:pos] = [ - '# WARNING: the following LICENSE value is a best guess - it is your', - '# responsibility to verify that the value is complete and correct.' - ] - del bbinfo['LICENSE'] - - src_uri_line = None - for pos, line in enumerate(lines_before): - if line.startswith('SRC_URI ='): - src_uri_line = pos - - if bbinfo: - mdinfo = [''] - for k in sorted(bbinfo): - v = bbinfo[k] - mdinfo.append('{} = "{}"'.format(k, v)) - if src_uri_line: - lines_before[src_uri_line-1:src_uri_line-1] = mdinfo - else: - lines_before.extend(mdinfo) + if bbvar not in extravalues and value: + extravalues[bbvar] = value mapped_deps, unmapped_deps = self.scan_setup_python_deps(srctree, setup_info, setup_non_literals) @@ -294,8 +288,8 @@ class PythonRecipeHandler(RecipeHandler): lines_after.append('# The upstream names may not correspond exactly to bitbake package names.') lines_after.append('#') lines_after.append('# Uncomment this line to enable all the optional features.') - lines_after.append('#PACKAGECONFIG ?= "{}"'.format(' '.join(k.lower() for k in extras_req.iterkeys()))) - for feature, feature_reqs in extras_req.iteritems(): + lines_after.append('#PACKAGECONFIG ?= "{}"'.format(' '.join(k.lower() for k in extras_req))) + for feature, feature_reqs in extras_req.items(): unmapped_deps.difference_update(feature_reqs) feature_req_deps = ('python-' + r.replace('.', '-').lower() for r in sorted(feature_reqs)) @@ -361,7 +355,7 @@ class PythonRecipeHandler(RecipeHandler): # Naive mapping of setup() arguments to PKG-INFO field names for d in [info, non_literals]: - for key, value in d.items(): + for key, value in list(d.items()): new_key = _map(key) if new_key != key: del d[key] @@ -436,14 +430,14 @@ class PythonRecipeHandler(RecipeHandler): return value value = info[variable] - if isinstance(value, basestring): + if isinstance(value, str): new_value = replace_value(search, replace, value) if new_value is None: del info[variable] elif new_value != value: info[variable] = new_value - elif hasattr(value, 'iteritems'): - for dkey, dvalue in value.iteritems(): + elif hasattr(value, 'items'): + for dkey, dvalue in list(value.items()): new_list = [] for pos, a_value in enumerate(dvalue): new_value = replace_value(search, replace, a_value) @@ -504,8 +498,10 @@ class PythonRecipeHandler(RecipeHandler): for dep in scanned_deps: mapped = provided_packages.get(dep) if mapped: + logger.debug('Mapped %s to %s' % (dep, mapped)) mapped_deps.add(mapped) else: + logger.debug('Could not map %s' % dep) unmapped_deps.add(dep) return mapped_deps, unmapped_deps @@ -516,7 +512,7 @@ class PythonRecipeHandler(RecipeHandler): except (OSError, subprocess.CalledProcessError): pass else: - for line in dep_output.splitlines(): + for line in dep_output.decode('utf-8').splitlines(): line = line.rstrip() dep, filename = line.split('\t', 1) if filename.endswith('/setup.py'): @@ -558,7 +554,7 @@ class PythonRecipeHandler(RecipeHandler): else: continue - for fn in files_info.iterkeys(): + for fn in files_info: for suffix in suffixes: if fn.endswith(suffix): break @@ -566,6 +562,8 @@ class PythonRecipeHandler(RecipeHandler): continue if fn.startswith(dynload_dir + os.sep): + if '/.debug/' in fn: + continue base = os.path.basename(fn) provided = base.split('.', 1)[0] packages[provided] = os.path.basename(pkgdatafile) @@ -608,7 +606,7 @@ def gather_setup_info(fileobj): visitor.visit(parsed) non_literals, extensions = {}, [] - for key, value in visitor.keywords.items(): + for key, value in list(visitor.keywords.items()): if key == 'ext_modules': if isinstance(value, list): for ext in value: @@ -640,7 +638,7 @@ class SetupScriptVisitor(ast.NodeVisitor): def visit_setup(self, node): call = LiteralAstTransform().visit(node) self.keywords = call.keywords - for k, v in self.keywords.iteritems(): + for k, v in self.keywords.items(): if has_non_literals(v): self.non_literals.append(k) @@ -706,10 +704,10 @@ class LiteralAstTransform(ast.NodeTransformer): def has_non_literals(value): if isinstance(value, ast.AST): return True - elif isinstance(value, basestring): + elif isinstance(value, str): return False - elif hasattr(value, 'itervalues'): - return any(has_non_literals(v) for v in value.itervalues()) + elif hasattr(value, 'values'): + return any(has_non_literals(v) for v in value.values()) elif hasattr(value, '__iter__'): return any(has_non_literals(v) for v in value) |