diff options
author | Enguerrand de Ribaucourt <enguerrand.de-ribaucourt@savoirfairelinux.com> | 2024-08-12 14:28:28 +0200 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2024-08-23 09:51:36 +0100 |
commit | 69bf37a3dd0470dc153bb7a21bd8f13a64bde2c3 (patch) | |
tree | cb531ea0bd3590e2f2b29a00156de6078027a5d8 /scripts/lib/recipetool/create.py | |
parent | 01d17cd5d42d1c9c349e1249bdacffb24d8446bb (diff) | |
download | poky-69bf37a3dd0470dc153bb7a21bd8f13a64bde2c3.tar.gz |
recipetool: create: split guess_license function
The npm recipetool handler redefines the license code the could be
unified. In order to do this refactoring, extract the bits we'll
need into separate functions.
guess_license() is renamed to find_licenses() and is split into
find_license_files() and match_licenses().
(From OE-Core rev: f1ec28feaea8ea6a2df894dd4ddba561c8a04ed2)
Signed-off-by: Enguerrand de Ribaucourt <enguerrand.de-ribaucourt@savoirfairelinux.com>
Signed-off-by: Alexandre Belloni <alexandre.belloni@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'scripts/lib/recipetool/create.py')
-rw-r--r-- | scripts/lib/recipetool/create.py | 34 |
1 files changed, 22 insertions, 12 deletions
diff --git a/scripts/lib/recipetool/create.py b/scripts/lib/recipetool/create.py index 066366e34f..c626844370 100644 --- a/scripts/lib/recipetool/create.py +++ b/scripts/lib/recipetool/create.py | |||
@@ -960,7 +960,7 @@ def handle_license_vars(srctree, lines_before, handled, extravalues, d): | |||
960 | # Someone else has already handled the license vars, just return their value | 960 | # Someone else has already handled the license vars, just return their value |
961 | return lichandled[0][1] | 961 | return lichandled[0][1] |
962 | 962 | ||
963 | licvalues = guess_license(srctree, d) | 963 | licvalues = find_licenses(srctree, d) |
964 | licenses = [] | 964 | licenses = [] |
965 | lic_files_chksum = [] | 965 | lic_files_chksum = [] |
966 | lic_unknown = [] | 966 | lic_unknown = [] |
@@ -1216,13 +1216,7 @@ def crunch_license(licfile): | |||
1216 | lictext = '' | 1216 | lictext = '' |
1217 | return md5val, lictext | 1217 | return md5val, lictext |
1218 | 1218 | ||
1219 | def guess_license(srctree, d): | 1219 | def find_license_files(srctree): |
1220 | import bb | ||
1221 | md5sums = get_license_md5sums(d) | ||
1222 | |||
1223 | crunched_md5sums = crunch_known_licenses(d) | ||
1224 | |||
1225 | licenses = [] | ||
1226 | licspecs = ['*LICEN[CS]E*', 'COPYING*', '*[Ll]icense*', 'LEGAL*', '[Ll]egal*', '*GPL*', 'README.lic*', 'COPYRIGHT*', '[Cc]opyright*', 'e[dp]l-v10'] | 1220 | licspecs = ['*LICEN[CS]E*', 'COPYING*', '*[Ll]icense*', 'LEGAL*', '[Ll]egal*', '*GPL*', 'README.lic*', 'COPYRIGHT*', '[Cc]opyright*', 'e[dp]l-v10'] |
1227 | skip_extensions = (".html", ".js", ".json", ".svg", ".ts", ".go") | 1221 | skip_extensions = (".html", ".js", ".json", ".svg", ".ts", ".go") |
1228 | licfiles = [] | 1222 | licfiles = [] |
@@ -1235,11 +1229,22 @@ def guess_license(srctree, d): | |||
1235 | fullpath = os.path.join(root, fn) | 1229 | fullpath = os.path.join(root, fn) |
1236 | if not fullpath in licfiles: | 1230 | if not fullpath in licfiles: |
1237 | licfiles.append(fullpath) | 1231 | licfiles.append(fullpath) |
1232 | |||
1233 | return licfiles | ||
1234 | |||
1235 | def match_licenses(licfiles, srctree, d): | ||
1236 | import bb | ||
1237 | md5sums = get_license_md5sums(d) | ||
1238 | |||
1239 | crunched_md5sums = crunch_known_licenses(d) | ||
1240 | |||
1241 | licenses = [] | ||
1238 | for licfile in sorted(licfiles): | 1242 | for licfile in sorted(licfiles): |
1239 | md5value = bb.utils.md5_file(licfile) | 1243 | resolved_licfile = d.expand(licfile) |
1244 | md5value = bb.utils.md5_file(resolved_licfile) | ||
1240 | license = md5sums.get(md5value, None) | 1245 | license = md5sums.get(md5value, None) |
1241 | if not license: | 1246 | if not license: |
1242 | crunched_md5, lictext = crunch_license(licfile) | 1247 | crunched_md5, lictext = crunch_license(resolved_licfile) |
1243 | license = crunched_md5sums.get(crunched_md5, None) | 1248 | license = crunched_md5sums.get(crunched_md5, None) |
1244 | if lictext and not license: | 1249 | if lictext and not license: |
1245 | license = 'Unknown' | 1250 | license = 'Unknown' |
@@ -1249,13 +1254,19 @@ def guess_license(srctree, d): | |||
1249 | if license: | 1254 | if license: |
1250 | licenses.append((license, os.path.relpath(licfile, srctree), md5value)) | 1255 | licenses.append((license, os.path.relpath(licfile, srctree), md5value)) |
1251 | 1256 | ||
1257 | return licenses | ||
1258 | |||
1259 | def find_licenses(srctree, d): | ||
1260 | licfiles = find_license_files(srctree) | ||
1261 | licenses = match_licenses(licfiles, srctree, d) | ||
1262 | |||
1252 | # FIXME should we grab at least one source file with a license header and add that too? | 1263 | # FIXME should we grab at least one source file with a license header and add that too? |
1253 | 1264 | ||
1254 | return licenses | 1265 | return licenses |
1255 | 1266 | ||
1256 | def split_pkg_licenses(licvalues, packages, outlines, fallback_licenses=None, pn='${PN}'): | 1267 | def split_pkg_licenses(licvalues, packages, outlines, fallback_licenses=None, pn='${PN}'): |
1257 | """ | 1268 | """ |
1258 | Given a list of (license, path, md5sum) as returned by guess_license(), | 1269 | Given a list of (license, path, md5sum) as returned by match_licenses(), |
1259 | a dict of package name to path mappings, write out a set of | 1270 | a dict of package name to path mappings, write out a set of |
1260 | package-specific LICENSE values. | 1271 | package-specific LICENSE values. |
1261 | """ | 1272 | """ |
@@ -1418,4 +1429,3 @@ def register_commands(subparsers): | |||
1418 | parser_create.add_argument('--devtool', action="store_true", help=argparse.SUPPRESS) | 1429 | parser_create.add_argument('--devtool', action="store_true", help=argparse.SUPPRESS) |
1419 | parser_create.add_argument('--mirrors', action="store_true", help='Enable PREMIRRORS and MIRRORS for source tree fetching (disabled by default).') | 1430 | parser_create.add_argument('--mirrors', action="store_true", help='Enable PREMIRRORS and MIRRORS for source tree fetching (disabled by default).') |
1420 | parser_create.set_defaults(func=create_recipe) | 1431 | parser_create.set_defaults(func=create_recipe) |
1421 | |||