diff options
author | Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com> | 2021-10-08 09:48:32 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2021-10-14 11:48:45 +0100 |
commit | 36965547e344eb9ac947062075bbe58e5e9b623c (patch) | |
tree | 4bdc6016240030a28be63d4ce3019af49fb73693 /scripts | |
parent | 4ca5b3fcb04d0f693ee1de4f19b8c9eb3b15b5ef (diff) | |
download | poky-36965547e344eb9ac947062075bbe58e5e9b623c.tar.gz |
recipetool: npm: Use README as license fallback
Use the README as license fallback if a license file is missing. Use the
linenumbers parameter of get_license_md5sums function to determine the
license text inside the README.
(From OE-Core rev: eff85c86f36673a1cb5a5dc8c66598e0dc457374)
Signed-off-by: Stefan Herbrechtsmeier <stefan.herbrechtsmeier@weidmueller.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts')
-rw-r--r-- | scripts/lib/recipetool/create_npm.py | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/scripts/lib/recipetool/create_npm.py b/scripts/lib/recipetool/create_npm.py index c939780931..3394a89970 100644 --- a/scripts/lib/recipetool/create_npm.py +++ b/scripts/lib/recipetool/create_npm.py | |||
@@ -6,6 +6,7 @@ | |||
6 | """Recipe creation tool - npm module support plugin""" | 6 | """Recipe creation tool - npm module support plugin""" |
7 | 7 | ||
8 | import json | 8 | import json |
9 | import logging | ||
9 | import os | 10 | import os |
10 | import re | 11 | import re |
11 | import sys | 12 | import sys |
@@ -14,8 +15,10 @@ import bb | |||
14 | from bb.fetch2.npm import NpmEnvironment | 15 | from bb.fetch2.npm import NpmEnvironment |
15 | from bb.fetch2.npmsw import foreach_dependencies | 16 | from bb.fetch2.npmsw import foreach_dependencies |
16 | from recipetool.create import RecipeHandler | 17 | from recipetool.create import RecipeHandler |
18 | from recipetool.create import get_license_md5sums | ||
17 | from recipetool.create import guess_license | 19 | from recipetool.create import guess_license |
18 | from recipetool.create import split_pkg_licenses | 20 | from recipetool.create import split_pkg_licenses |
21 | logger = logging.getLogger('recipetool') | ||
19 | 22 | ||
20 | TINFOIL = None | 23 | TINFOIL = None |
21 | 24 | ||
@@ -115,17 +118,36 @@ class NpmRecipeHandler(RecipeHandler): | |||
115 | 118 | ||
116 | def _handle_licenses(self, srctree, shrinkwrap_file, dev): | 119 | def _handle_licenses(self, srctree, shrinkwrap_file, dev): |
117 | """Return the extra license files and the list of packages""" | 120 | """Return the extra license files and the list of packages""" |
121 | licfiles = [] | ||
118 | packages = {} | 122 | packages = {} |
119 | 123 | ||
120 | # Handle the parent package | 124 | # Handle the parent package |
121 | packages["${PN}"] = "" | 125 | packages["${PN}"] = "" |
122 | 126 | ||
127 | def _licfiles_append_fallback_readme_files(destdir): | ||
128 | """Append README files as fallback to license files if a license files is missing""" | ||
129 | |||
130 | fallback = True | ||
131 | readmes = [] | ||
132 | basedir = os.path.join(srctree, destdir) | ||
133 | for fn in os.listdir(basedir): | ||
134 | upper = fn.upper() | ||
135 | if upper.startswith("README"): | ||
136 | fullpath = os.path.join(basedir, fn) | ||
137 | readmes.append(fullpath) | ||
138 | if upper.startswith("COPYING") or "LICENCE" in upper or "LICENSE" in upper: | ||
139 | fallback = False | ||
140 | if fallback: | ||
141 | for readme in readmes: | ||
142 | licfiles.append(os.path.relpath(readme, srctree)) | ||
143 | |||
123 | # Handle the dependencies | 144 | # Handle the dependencies |
124 | def _handle_dependency(name, params, deptree): | 145 | def _handle_dependency(name, params, deptree): |
125 | suffix = "-".join([self._npm_name(dep) for dep in deptree]) | 146 | suffix = "-".join([self._npm_name(dep) for dep in deptree]) |
126 | destdirs = [os.path.join("node_modules", dep) for dep in deptree] | 147 | destdirs = [os.path.join("node_modules", dep) for dep in deptree] |
127 | destdir = os.path.join(*destdirs) | 148 | destdir = os.path.join(*destdirs) |
128 | packages["${PN}-" + suffix] = destdir | 149 | packages["${PN}-" + suffix] = destdir |
150 | _licfiles_append_fallback_readme_files(destdir) | ||
129 | 151 | ||
130 | with open(shrinkwrap_file, "r") as f: | 152 | with open(shrinkwrap_file, "r") as f: |
131 | shrinkwrap = json.load(f) | 153 | shrinkwrap = json.load(f) |
@@ -237,7 +259,35 @@ class NpmRecipeHandler(RecipeHandler): | |||
237 | 259 | ||
238 | bb.note("Handling licences ...") | 260 | bb.note("Handling licences ...") |
239 | (licfiles, packages) = self._handle_licenses(srctree, shrinkwrap_file, dev) | 261 | (licfiles, packages) = self._handle_licenses(srctree, shrinkwrap_file, dev) |
240 | split_pkg_licenses(guess_license(srctree, d), packages, lines_after, []) | 262 | |
263 | def _guess_odd_license(licfiles): | ||
264 | import bb | ||
265 | |||
266 | md5sums = get_license_md5sums(d, linenumbers=True) | ||
267 | |||
268 | chksums = [] | ||
269 | licenses = [] | ||
270 | for licfile in licfiles: | ||
271 | f = os.path.join(srctree, licfile) | ||
272 | md5value = bb.utils.md5_file(f) | ||
273 | (license, beginline, endline, md5) = md5sums.get(md5value, | ||
274 | (None, "", "", "")) | ||
275 | if not license: | ||
276 | license = "Unknown" | ||
277 | logger.info("Please add the following line for '%s' to a " | ||
278 | "'lib/recipetool/licenses.csv' and replace `Unknown`, " | ||
279 | "`X`, `Y` and `MD5` with the license, begin line, " | ||
280 | "end line and partial MD5 checksum:\n" \ | ||
281 | "%s,Unknown,X,Y,MD5" % (licfile, md5value)) | ||
282 | chksums.append("file://%s%s%s;md5=%s" % (licfile, | ||
283 | ";beginline=%s" % (beginline) if beginline else "", | ||
284 | ";endline=%s" % (endline) if endline else "", | ||
285 | md5 if md5 else md5value)) | ||
286 | licenses.append((license, licfile, md5value)) | ||
287 | return (licenses, chksums) | ||
288 | |||
289 | (licenses, extravalues["LIC_FILES_CHKSUM"]) = _guess_odd_license(licfiles) | ||
290 | split_pkg_licenses([*licenses, *guess_license(srctree, d)], packages, lines_after) | ||
241 | 291 | ||
242 | classes.append("npm") | 292 | classes.append("npm") |
243 | handled.append("buildsystem") | 293 | handled.append("buildsystem") |