summaryrefslogtreecommitdiffstats
path: root/scripts/lib/recipetool/create_npm.py
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2016-03-09 17:48:52 +1300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-03-09 17:00:29 +0000
commit91455005b65db1b6caededbcac0f08a0cfb660f3 (patch)
tree5b7e917a5560985f743d99475b722bc726f00660 /scripts/lib/recipetool/create_npm.py
parentd46827cfd322554b57c3fc774b4d914f6e449d75 (diff)
downloadpoky-91455005b65db1b6caededbcac0f08a0cfb660f3.tar.gz
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. (From OE-Core rev: 8226805f83d21e7c1d2ba21969f3e8ee4b137496) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/recipetool/create_npm.py')
-rw-r--r--scripts/lib/recipetool/create_npm.py57
1 files changed, 54 insertions, 3 deletions
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 @@
17 17
18import logging 18import logging
19import json 19import json
20from recipetool.create import RecipeHandler 20from recipetool.create import RecipeHandler, split_pkg_licenses
21 21
22logger = logging.getLogger('recipetool') 22logger = logging.getLogger('recipetool')
23 23
24 24
25class NpmRecipeHandler(RecipeHandler): 25class NpmRecipeHandler(RecipeHandler):
26 def _handle_license(self, data):
27 '''
28 Handle the license value from an npm package.json file
29 '''
30 license = None
31 if 'license' in data:
32 license = data['license']
33 if isinstance(license, dict):
34 license = license.get('type', None)
35 return None
36
26 def process(self, srctree, classes, lines_before, lines_after, handled, extravalues): 37 def process(self, srctree, classes, lines_before, lines_after, handled, extravalues):
38 import oe
39 from collections import OrderedDict
40
27 if 'buildsystem' in handled: 41 if 'buildsystem' in handled:
28 return False 42 return False
29 43
44 def read_package_json(fn):
45 with open(fn, 'r') as f:
46 return json.loads(f.read())
47
30 files = RecipeHandler.checkfiles(srctree, ['package.json']) 48 files = RecipeHandler.checkfiles(srctree, ['package.json'])
31 if files: 49 if files:
32 with open(files[0], 'r') as f: 50 data = read_package_json(files[0])
33 data = json.loads(f.read())
34 if 'name' in data and 'version' in data: 51 if 'name' in data and 'version' in data:
35 extravalues['PN'] = data['name'] 52 extravalues['PN'] = data['name']
36 extravalues['PV'] = data['version'] 53 extravalues['PV'] = data['version']
@@ -40,6 +57,40 @@ class NpmRecipeHandler(RecipeHandler):
40 lines_before.append('SUMMARY = "%s"' % data['description']) 57 lines_before.append('SUMMARY = "%s"' % data['description'])
41 if 'homepage' in data: 58 if 'homepage' in data:
42 lines_before.append('HOMEPAGE = "%s"' % data['homepage']) 59 lines_before.append('HOMEPAGE = "%s"' % data['homepage'])
60
61 # Split each npm module out to is own package
62 npmpackages = oe.package.npm_split_package_dirs(srctree)
63 for item in handled:
64 if isinstance(item, tuple):
65 if item[0] == 'license':
66 licvalues = item[1]
67 break
68 if licvalues:
69 # Augment the license list with information we have in the packages
70 licenses = {}
71 license = self._handle_license(data)
72 if license:
73 licenses['${PN}'] = license
74 for pkgname, pkgitem in npmpackages.iteritems():
75 _, pdata = pkgitem
76 license = self._handle_license(pdata)
77 if license:
78 licenses[pkgname] = license
79 # Now write out the package-specific license values
80 # We need to strip out the json data dicts for this since split_pkg_licenses
81 # isn't expecting it
82 packages = OrderedDict((x,y[0]) for x,y in npmpackages.iteritems())
83 packages['${PN}'] = ''
84 pkglicenses = split_pkg_licenses(licvalues, packages, lines_after, licenses)
85 all_licenses = list(set([item for pkglicense in pkglicenses.values() for item in pkglicense]))
86 # Go back and update the LICENSE value since we have a bit more
87 # information than when that was written out (and we know all apply
88 # vs. there being a choice, so we can join them with &)
89 for i, line in enumerate(lines_before):
90 if line.startswith('LICENSE = '):
91 lines_before[i] = 'LICENSE = "%s"' % ' & '.join(all_licenses)
92 break
93
43 return True 94 return True
44 95
45 return False 96 return False