diff options
| -rw-r--r-- | meta/lib/oe/license_finder.py | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/meta/lib/oe/license_finder.py b/meta/lib/oe/license_finder.py index 16f5d7c94c..4f2bb661fd 100644 --- a/meta/lib/oe/license_finder.py +++ b/meta/lib/oe/license_finder.py | |||
| @@ -120,14 +120,34 @@ def _crunch_license(licfile): | |||
| 120 | return md5val | 120 | return md5val |
| 121 | 121 | ||
| 122 | 122 | ||
| 123 | def find_license_files(srctree, first_only=False): | 123 | def find_license_files(srctree, first_only=False, bottom=""): |
| 124 | """ | 124 | """ |
| 125 | Search srctree for files that look like they could be licenses. | 125 | Search srctree for files that look like they could be licenses. |
| 126 | If first_only is True, only return the first file found. | 126 | If first_only is True, only return the first file found. |
| 127 | If bottom is not empty, start at bottom and continue upwards to the top. | ||
| 127 | """ | 128 | """ |
| 128 | licspecs = ['*LICEN[CS]E*', 'COPYING*', '*[Ll]icense*', 'LEGAL*', '[Ll]egal*', '*GPL*', 'README.lic*', 'COPYRIGHT*', '[Cc]opyright*', 'e[dp]l-v10'] | 129 | licspecs = ['*LICEN[CS]E*', 'COPYING*', '*[Ll]icense*', 'LEGAL*', '[Ll]egal*', '*GPL*', 'README.lic*', 'COPYRIGHT*', '[Cc]opyright*', 'e[dp]l-v10'] |
| 129 | skip_extensions = (".html", ".js", ".json", ".svg", ".ts", ".go", ".sh") | 130 | skip_extensions = (".html", ".js", ".json", ".svg", ".ts", ".go", ".sh") |
| 130 | licfiles = [] | 131 | licfiles = [] |
| 132 | if bottom: | ||
| 133 | srcdir = bottom | ||
| 134 | while srcdir.startswith(srctree): | ||
| 135 | files = [] | ||
| 136 | with os.scandir(srcdir) as it: | ||
| 137 | for entry in it: | ||
| 138 | if entry.is_file(): | ||
| 139 | files.append(entry.name) | ||
| 140 | for name in sorted(files): | ||
| 141 | if name.endswith(skip_extensions): | ||
| 142 | continue | ||
| 143 | for spec in licspecs: | ||
| 144 | if fnmatch.fnmatch(name, spec): | ||
| 145 | licfiles.append(os.path.join(srcdir, name)) | ||
| 146 | if first_only: | ||
| 147 | return licfiles | ||
| 148 | srcdir = os.path.dirname(srcdir) | ||
| 149 | return licfiles | ||
| 150 | |||
| 131 | for root, dirs, files in os.walk(srctree): | 151 | for root, dirs, files in os.walk(srctree): |
| 132 | # Sort files so that LICENSE is before LICENSE.subcomponent, which is | 152 | # Sort files so that LICENSE is before LICENSE.subcomponent, which is |
| 133 | # meaningful if first_only is set. | 153 | # meaningful if first_only is set. |
| @@ -177,3 +197,8 @@ def find_licenses(srctree, d, first_only=False, extra_hashes={}): | |||
| 177 | # FIXME should we grab at least one source file with a license header and add that too? | 197 | # FIXME should we grab at least one source file with a license header and add that too? |
| 178 | 198 | ||
| 179 | return licenses | 199 | return licenses |
| 200 | |||
| 201 | |||
| 202 | def find_licenses_up(srcdir, topdir, d, first_only=False, extra_hashes={}): | ||
| 203 | licfiles = find_license_files(topdir, first_only, srcdir) | ||
| 204 | return match_licenses(licfiles, topdir, d, extra_hashes) | ||
