diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2016-03-09 17:48:52 +1300 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-03-09 16:59:56 +0000 |
commit | 8226805f83d21e7c1d2ba21969f3e8ee4b137496 (patch) | |
tree | 938c463cd97418c033fb576254036e68af60c776 /scripts | |
parent | 553bb4ea5d51be5179e7d8c019740cf61ece76ea (diff) | |
download | openembedded-core-8226805f83d21e7c1d2ba21969f3e8ee4b137496.tar.gz openembedded-core-8226805f83d21e7c1d2ba21969f3e8ee4b137496.tar.bz2 openembedded-core-8226805f83d21e7c1d2ba21969f3e8ee4b137496.zip |
recipetool: create: split npm module dependencies into packages
Rather than rolling all of an npm module's dependencies into the same
package, split them into one module per package, setting the SUMMARY and
PKGV values from the package.json file for each package. Additionally,
mark each package with the appropriate license using the license
scanning we already do, falling back to the license stated in the
package.json file for the module if unknown. All of this is mostly in
aid of ensuring all modules and their licenses now show up in the
manifests for the image.
Additionally we set the main LICENSE value more concretely once we've
calculated the per-package licenses, since we have more information at
that point.
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/recipetool/create.py | 28 | ||||
-rw-r--r-- | scripts/lib/recipetool/create_npm.py | 57 |
2 files changed, 82 insertions, 3 deletions
diff --git a/scripts/lib/recipetool/create.py b/scripts/lib/recipetool/create.py index 718f2aaf5b..43c07848c2 100644 --- a/scripts/lib/recipetool/create.py +++ b/scripts/lib/recipetool/create.py @@ -544,6 +544,7 @@ def create_recipe(args): # Apply the handlers handled = [] + handled.append(('license', licvalues)) if args.binary: classes.append('bin_package') @@ -815,6 +816,33 @@ def guess_license(srctree): return licenses +def split_pkg_licenses(licvalues, packages, outlines, fallback_licenses=None, pn='${PN}'): + """ + Given a list of (license, path, md5sum) as returned by guess_license(), + a dict of package name to path mappings, write out a set of + package-specific LICENSE values. + """ + pkglicenses = {pn: []} + for license, licpath, _ in licvalues: + for pkgname, pkgpath in packages.iteritems(): + if licpath.startswith(pkgpath + '/'): + if pkgname in pkglicenses: + pkglicenses[pkgname].append(license) + else: + pkglicenses[pkgname] = [license] + break + else: + # Accumulate on the main package + pkglicenses[pn].append(license) + outlicenses = {} + for pkgname in packages: + license = ' '.join(list(set(pkglicenses.get(pkgname, ['Unknown'])))) + if license == 'Unknown' and pkgname in fallback_licenses: + license = fallback_licenses[pkgname] + outlines.append('LICENSE_%s = "%s"' % (pkgname, license)) + outlicenses[pkgname] = license.split() + return outlicenses + def read_pkgconfig_provides(d): pkgdatadir = d.getVar('PKGDATA_DIR', True) pkgmap = {} diff --git a/scripts/lib/recipetool/create_npm.py b/scripts/lib/recipetool/create_npm.py index 0e33cc9a1e..4bf6caed5c 100644 --- a/scripts/lib/recipetool/create_npm.py +++ b/scripts/lib/recipetool/create_npm.py @@ -17,20 +17,37 @@ import logging import json -from recipetool.create import RecipeHandler +from recipetool.create import RecipeHandler, split_pkg_licenses logger = logging.getLogger('recipetool') class NpmRecipeHandler(RecipeHandler): + def _handle_license(self, data): + ''' + Handle the license value from an npm package.json file + ''' + license = None + if 'license' in data: + license = data['license'] + if isinstance(license, dict): + license = license.get('type', None) + return None + def process(self, srctree, classes, lines_before, lines_after, handled, extravalues): + import oe + from collections import OrderedDict + if 'buildsystem' in handled: return False + def read_package_json(fn): + with open(fn, 'r') as f: + return json.loads(f.read()) + files = RecipeHandler.checkfiles(srctree, ['package.json']) if files: - with open(files[0], 'r') as f: - data = json.loads(f.read()) + data = read_package_json(files[0]) if 'name' in data and 'version' in data: extravalues['PN'] = data['name'] extravalues['PV'] = data['version'] @@ -40,6 +57,40 @@ class NpmRecipeHandler(RecipeHandler): lines_before.append('SUMMARY = "%s"' % data['description']) if 'homepage' in data: lines_before.append('HOMEPAGE = "%s"' % data['homepage']) + + # Split each npm module out to is own package + npmpackages = oe.package.npm_split_package_dirs(srctree) + for item in handled: + if isinstance(item, tuple): + if item[0] == 'license': + licvalues = item[1] + break + if licvalues: + # Augment the license list with information we have in the packages + licenses = {} + license = self._handle_license(data) + if license: + licenses['${PN}'] = license + for pkgname, pkgitem in npmpackages.iteritems(): + _, pdata = pkgitem + license = self._handle_license(pdata) + if license: + licenses[pkgname] = license + # Now write out the package-specific license values + # We need to strip out the json data dicts for this since split_pkg_licenses + # isn't expecting it + packages = OrderedDict((x,y[0]) for x,y in npmpackages.iteritems()) + packages['${PN}'] = '' + pkglicenses = split_pkg_licenses(licvalues, packages, lines_after, licenses) + all_licenses = list(set([item for pkglicense in pkglicenses.values() for item in pkglicense])) + # Go back and update the LICENSE value since we have a bit more + # information than when that was written out (and we know all apply + # vs. there being a choice, so we can join them with &) + for i, line in enumerate(lines_before): + if line.startswith('LICENSE = '): + lines_before[i] = 'LICENSE = "%s"' % ' & '.join(all_licenses) + break + return True return False |