summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--scripts/lib/recipetool/create_npm.py46
1 files changed, 46 insertions, 0 deletions
diff --git a/scripts/lib/recipetool/create_npm.py b/scripts/lib/recipetool/create_npm.py
index 7f0d8a04a3..579b7ae48a 100644
--- a/scripts/lib/recipetool/create_npm.py
+++ b/scripts/lib/recipetool/create_npm.py
@@ -12,7 +12,10 @@ import sys
12import tempfile 12import tempfile
13import bb 13import bb
14from bb.fetch2.npm import NpmEnvironment 14from bb.fetch2.npm import NpmEnvironment
15from bb.fetch2.npmsw import foreach_dependencies
15from recipetool.create import RecipeHandler 16from recipetool.create import RecipeHandler
17from recipetool.create import guess_license
18from recipetool.create import split_pkg_licenses
16 19
17TINFOIL = None 20TINFOIL = None
18 21
@@ -110,6 +113,36 @@ class NpmRecipeHandler(RecipeHandler):
110 113
111 return os.path.join(srctree, "npm-shrinkwrap.json") 114 return os.path.join(srctree, "npm-shrinkwrap.json")
112 115
116 def _handle_licenses(self, srctree, shrinkwrap_file, dev):
117 """Return the extra license files and the list of packages"""
118 licfiles = []
119 packages = {}
120
121 def _licfiles_append(licfile):
122 """Append 'licfile' to the license files list"""
123 licfilepath = os.path.join(srctree, licfile)
124 licmd5 = bb.utils.md5_file(licfilepath)
125 licfiles.append("file://%s;md5=%s" % (licfile, licmd5))
126
127 # Handle the parent package
128 _licfiles_append("package.json")
129 packages["${PN}"] = ""
130
131 # Handle the dependencies
132 def _handle_dependency(name, params, deptree):
133 suffix = "-".join([self._npm_name(dep) for dep in deptree])
134 destdirs = [os.path.join("node_modules", dep) for dep in deptree]
135 destdir = os.path.join(*destdirs)
136 _licfiles_append(os.path.join(destdir, "package.json"))
137 packages["${PN}-" + suffix] = destdir
138
139 with open(shrinkwrap_file, "r") as f:
140 shrinkwrap = json.load(f)
141
142 foreach_dependencies(shrinkwrap, _handle_dependency, dev)
143
144 return licfiles, packages
145
113 def process(self, srctree, classes, lines_before, lines_after, handled, extravalues): 146 def process(self, srctree, classes, lines_before, lines_after, handled, extravalues):
114 """Handle the npm recipe creation""" 147 """Handle the npm recipe creation"""
115 148
@@ -199,6 +232,19 @@ class NpmRecipeHandler(RecipeHandler):
199 (_, newlines) = bb.utils.edit_metadata(lines_before, ["SRC_URI"], _handle_srcuri) 232 (_, newlines) = bb.utils.edit_metadata(lines_before, ["SRC_URI"], _handle_srcuri)
200 lines_before[:] = [line.rstrip('\n') for line in newlines] 233 lines_before[:] = [line.rstrip('\n') for line in newlines]
201 234
235 # In order to generate correct licence checksums in the recipe the
236 # dependencies have to be fetched again using the npmsw url
237 bb.note("Fetching npm dependencies ...")
238 bb.utils.remove(os.path.join(srctree, "node_modules"), recurse=True)
239 fetcher = bb.fetch2.Fetch([url_local], d)
240 fetcher.download()
241 fetcher.unpack(srctree)
242
243 bb.note("Handling licences ...")
244 (licfiles, packages) = self._handle_licenses(srctree, shrinkwrap_file, dev)
245 extravalues["LIC_FILES_CHKSUM"] = licfiles
246 split_pkg_licenses(guess_license(srctree, d), packages, lines_after, [])
247
202 classes.append("npm") 248 classes.append("npm")
203 handled.append("buildsystem") 249 handled.append("buildsystem")
204 250