summaryrefslogtreecommitdiffstats
path: root/scripts
diff options
context:
space:
mode:
Diffstat (limited to 'scripts')
-rw-r--r--scripts/lib/recipetool/create.py34
-rw-r--r--scripts/lib/recipetool/create_go.py4
-rw-r--r--scripts/lib/recipetool/create_npm.py4
3 files changed, 26 insertions, 16 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
1219def guess_license(srctree, d): 1219def 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
1235def 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
1259def 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
1256def split_pkg_licenses(licvalues, packages, outlines, fallback_licenses=None, pn='${PN}'): 1267def 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
diff --git a/scripts/lib/recipetool/create_go.py b/scripts/lib/recipetool/create_go.py
index a85a2f2786..5cc53931f0 100644
--- a/scripts/lib/recipetool/create_go.py
+++ b/scripts/lib/recipetool/create_go.py
@@ -14,7 +14,7 @@ from collections import namedtuple
14from enum import Enum 14from enum import Enum
15from html.parser import HTMLParser 15from html.parser import HTMLParser
16from recipetool.create import RecipeHandler, handle_license_vars 16from recipetool.create import RecipeHandler, handle_license_vars
17from recipetool.create import guess_license, tidy_licenses, fixup_license 17from recipetool.create import find_licenses, tidy_licenses, fixup_license
18from recipetool.create import determine_from_url 18from recipetool.create import determine_from_url
19from urllib.error import URLError, HTTPError 19from urllib.error import URLError, HTTPError
20 20
@@ -624,7 +624,7 @@ class GoRecipeHandler(RecipeHandler):
624 624
625 licenses = [] 625 licenses = []
626 lic_files_chksum = [] 626 lic_files_chksum = []
627 licvalues = guess_license(tmp_vendor_dir, d) 627 licvalues = find_licenses(tmp_vendor_dir, d)
628 shutil.rmtree(tmp_vendor_dir) 628 shutil.rmtree(tmp_vendor_dir)
629 629
630 if licvalues: 630 if licvalues:
diff --git a/scripts/lib/recipetool/create_npm.py b/scripts/lib/recipetool/create_npm.py
index dd0ac01c3e..78dc248f31 100644
--- a/scripts/lib/recipetool/create_npm.py
+++ b/scripts/lib/recipetool/create_npm.py
@@ -17,7 +17,7 @@ from bb.fetch2.npm import npm_package
17from bb.fetch2.npmsw import foreach_dependencies 17from bb.fetch2.npmsw import foreach_dependencies
18from recipetool.create import RecipeHandler 18from recipetool.create import RecipeHandler
19from recipetool.create import get_license_md5sums 19from recipetool.create import get_license_md5sums
20from recipetool.create import guess_license 20from recipetool.create import find_licenses
21from recipetool.create import split_pkg_licenses 21from recipetool.create import split_pkg_licenses
22logger = logging.getLogger('recipetool') 22logger = logging.getLogger('recipetool')
23 23
@@ -320,7 +320,7 @@ class NpmRecipeHandler(RecipeHandler):
320 return (licenses, chksums, fallback_licenses) 320 return (licenses, chksums, fallback_licenses)
321 321
322 (licenses, extravalues["LIC_FILES_CHKSUM"], fallback_licenses) = _guess_odd_license(licfiles) 322 (licenses, extravalues["LIC_FILES_CHKSUM"], fallback_licenses) = _guess_odd_license(licfiles)
323 split_pkg_licenses([*licenses, *guess_license(srctree, d)], packages, lines_after, fallback_licenses) 323 split_pkg_licenses([*licenses, *find_licenses(srctree, d)], packages, lines_after, fallback_licenses)
324 324
325 classes.append("npm") 325 classes.append("npm")
326 handled.append("buildsystem") 326 handled.append("buildsystem")