diff options
author | Jean-Marie LEMETAYER <jean-marie.lemetayer@savoirfairelinux.com> | 2020-01-24 18:07:38 +0100 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2020-01-27 16:48:09 +0000 |
commit | cfa5544005a37df684463367eab7f4cf376cd1a9 (patch) | |
tree | 11d4cb31cb00780f1d4f3f1a08a3bd1a4c2dc0ff /scripts/lib/recipetool | |
parent | 6fd9cebc98b5212fd5b27b166c053846c494c09b (diff) | |
download | poky-cfa5544005a37df684463367eab7f4cf376cd1a9.tar.gz |
recipetool/create_npm: handle the licenses of the dependencies
As usual the 'LICENSE' and the 'LIC_FILES_CHKSUM' values reflects all
the license files discovered in the source tree (including the
dependencies).
For npm recipes the 'LIC_FILES_CHKSUM' value contains also the status of
the 'package.json' file of every packages as it contains license
informations.
Finally each package has a separate 'LICENSE_${PN}-package-name' value
which describes its license.
(From OE-Core rev: 9a70d4996c84b277f423eda5aac4acbe344599f4)
Signed-off-by: Jean-Marie LEMETAYER <jean-marie.lemetayer@savoirfairelinux.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/recipetool')
-rw-r--r-- | scripts/lib/recipetool/create_npm.py | 46 |
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 | |||
12 | import tempfile | 12 | import tempfile |
13 | import bb | 13 | import bb |
14 | from bb.fetch2.npm import NpmEnvironment | 14 | from bb.fetch2.npm import NpmEnvironment |
15 | from bb.fetch2.npmsw import foreach_dependencies | ||
15 | from recipetool.create import RecipeHandler | 16 | from recipetool.create import RecipeHandler |
17 | from recipetool.create import guess_license | ||
18 | from recipetool.create import split_pkg_licenses | ||
16 | 19 | ||
17 | TINFOIL = None | 20 | TINFOIL = 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 | ||