diff options
| -rw-r--r-- | meta/lib/oe/license_finder.py | 65 |
1 files changed, 29 insertions, 36 deletions
diff --git a/meta/lib/oe/license_finder.py b/meta/lib/oe/license_finder.py index cacb4cb19d..1bdc39e1c5 100644 --- a/meta/lib/oe/license_finder.py +++ b/meta/lib/oe/license_finder.py | |||
| @@ -11,24 +11,18 @@ import os | |||
| 11 | import re | 11 | import re |
| 12 | 12 | ||
| 13 | import bb | 13 | import bb |
| 14 | import bb.utils | ||
| 14 | 15 | ||
| 15 | logger = logging.getLogger("BitBake.OE.LicenseFinder") | 16 | logger = logging.getLogger("BitBake.OE.LicenseFinder") |
| 16 | 17 | ||
| 17 | def get_license_md5sums(d): | 18 | def _load_hash_csv(d): |
| 18 | import bb.utils | 19 | """ |
| 20 | Load a mapping of (checksum: license name) from all files/license-hashes.csv | ||
| 21 | files that can be found in the available layers. | ||
| 22 | """ | ||
| 19 | import csv | 23 | import csv |
| 20 | md5sums = {} | 24 | md5sums = {} |
| 21 | 25 | ||
| 22 | # Gather md5sums of license files in common license dir | ||
| 23 | commonlicdir = d.getVar('COMMON_LICENSE_DIR') | ||
| 24 | for fn in os.listdir(commonlicdir): | ||
| 25 | md5value = bb.utils.md5_file(os.path.join(commonlicdir, fn)) | ||
| 26 | md5sums[md5value] = fn | ||
| 27 | |||
| 28 | # The following were extracted from common values in various recipes | ||
| 29 | # (double checking the license against the license file itself, not just | ||
| 30 | # the LICENSE value in the recipe) | ||
| 31 | |||
| 32 | # Read license md5sums from csv file | 26 | # Read license md5sums from csv file |
| 33 | for path in d.getVar('BBPATH').split(':'): | 27 | for path in d.getVar('BBPATH').split(':'): |
| 34 | csv_path = os.path.join(path, 'files', 'license-hashes.csv') | 28 | csv_path = os.path.join(path, 'files', 'license-hashes.csv') |
| @@ -41,28 +35,28 @@ def get_license_md5sums(d): | |||
| 41 | return md5sums | 35 | return md5sums |
| 42 | 36 | ||
| 43 | 37 | ||
| 44 | def crunch_known_licenses(d): | 38 | def _crunch_known_licenses(d): |
| 45 | ''' | 39 | """ |
| 46 | Calculate the MD5 checksums for the crunched versions of all common | 40 | Calculate the MD5 checksums for the original and "crunched" versions of all |
| 47 | licenses. Also add additional known checksums. | 41 | known licenses. |
| 48 | ''' | 42 | """ |
| 49 | 43 | md5sums = {} | |
| 50 | crunched_md5sums = {} | ||
| 51 | 44 | ||
| 52 | commonlicdir = d.getVar('COMMON_LICENSE_DIR') | 45 | lic_dirs = [d.getVar('COMMON_LICENSE_DIR')] + (d.getVar('LICENSE_PATH') or "").split() |
| 53 | for fn in sorted(os.listdir(commonlicdir)): | 46 | for lic_dir in lic_dirs: |
| 54 | md5value = crunch_license(os.path.join(commonlicdir, fn)) | 47 | for fn in os.listdir(lic_dir): |
| 55 | if md5value not in crunched_md5sums: | 48 | path = os.path.join(lic_dir, fn) |
| 56 | crunched_md5sums[md5value] = fn | 49 | # Hash the exact contents |
| 57 | elif fn != crunched_md5sums[md5value]: | 50 | md5value = bb.utils.md5_file(path) |
| 58 | bb.debug(2, "crunched_md5sums['%s'] is already set to '%s' rather than '%s'" % (md5value, crunched_md5sums[md5value], fn)) | 51 | md5sums[md5value] = fn |
| 59 | else: | 52 | # Also hash a "crunched" version |
| 60 | bb.debug(2, "crunched_md5sums['%s'] is already set to '%s'" % (md5value, crunched_md5sums[md5value])) | 53 | md5value = _crunch_license(path) |
| 54 | md5sums[md5value] = fn | ||
| 61 | 55 | ||
| 62 | return crunched_md5sums | 56 | return md5sums |
| 63 | 57 | ||
| 64 | 58 | ||
| 65 | def crunch_license(licfile): | 59 | def _crunch_license(licfile): |
| 66 | ''' | 60 | ''' |
| 67 | Remove non-material text from a license file and then calculate its | 61 | Remove non-material text from a license file and then calculate its |
| 68 | md5sum. This works well for licenses that contain a copyright statement, | 62 | md5sum. This works well for licenses that contain a copyright statement, |
| @@ -152,10 +146,9 @@ def find_license_files(srctree, first_only=False): | |||
| 152 | 146 | ||
| 153 | 147 | ||
| 154 | def match_licenses(licfiles, srctree, d): | 148 | def match_licenses(licfiles, srctree, d): |
| 155 | import bb | 149 | md5sums = {} |
| 156 | md5sums = get_license_md5sums(d) | 150 | md5sums.update(_load_hash_csv(d)) |
| 157 | 151 | md5sums.update(_crunch_known_licenses(d)) | |
| 158 | crunched_md5sums = crunch_known_licenses(d) | ||
| 159 | 152 | ||
| 160 | licenses = [] | 153 | licenses = [] |
| 161 | for licfile in sorted(licfiles): | 154 | for licfile in sorted(licfiles): |
| @@ -163,8 +156,8 @@ def match_licenses(licfiles, srctree, d): | |||
| 163 | md5value = bb.utils.md5_file(resolved_licfile) | 156 | md5value = bb.utils.md5_file(resolved_licfile) |
| 164 | license = md5sums.get(md5value, None) | 157 | license = md5sums.get(md5value, None) |
| 165 | if not license: | 158 | if not license: |
| 166 | crunched_md5 = crunch_license(resolved_licfile) | 159 | crunched_md5 = _crunch_license(resolved_licfile) |
| 167 | license = crunched_md5sums.get(crunched_md5, None) | 160 | license = md5sums.get(crunched_md5, None) |
| 168 | if not license: | 161 | if not license: |
| 169 | license = 'Unknown' | 162 | license = 'Unknown' |
| 170 | logger.info("Please add the following line for '%s' to a 'license-hashes.csv' " \ | 163 | logger.info("Please add the following line for '%s' to a 'license-hashes.csv' " \ |
