diff options
| author | Ross Burton <ross.burton@arm.com> | 2025-06-13 14:16:14 +0100 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-06-16 17:57:30 +0100 |
| commit | f516c4ccf53be86866686e28a98c798bdc1087d4 (patch) | |
| tree | 97af7ae8e455b44bc6f133cb340c20edfa97fe24 | |
| parent | dc73e3083c3c2449625955c9afce594794cbddfa (diff) | |
| download | poky-f516c4ccf53be86866686e28a98c798bdc1087d4.tar.gz | |
oe/license_finder: add first_only argument to find_licenses()
It may be desired to find only the "top-level" license file instead of
every potential candidate, so add a first_only argument (defaulting to
False to preserve existing behaviour) to return just the first license
found.
(From OE-Core rev: 995936ffda02a1def1863490ec315783a7470c72)
Signed-off-by: Ross Burton <ross.burton@arm.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -rw-r--r-- | meta/lib/oe/license_finder.py | 16 |
1 files changed, 12 insertions, 4 deletions
diff --git a/meta/lib/oe/license_finder.py b/meta/lib/oe/license_finder.py index d5030c033e..96961658e8 100644 --- a/meta/lib/oe/license_finder.py +++ b/meta/lib/oe/license_finder.py | |||
| @@ -191,12 +191,18 @@ def crunch_license(licfile): | |||
| 191 | return md5val, lictext | 191 | return md5val, lictext |
| 192 | 192 | ||
| 193 | 193 | ||
| 194 | def find_license_files(srctree): | 194 | def find_license_files(srctree, first_only=False): |
| 195 | """ | ||
| 196 | Search srctree for files that look like they could be licenses. | ||
| 197 | If first_only is True, only return the first file found. | ||
| 198 | """ | ||
| 195 | licspecs = ['*LICEN[CS]E*', 'COPYING*', '*[Ll]icense*', 'LEGAL*', '[Ll]egal*', '*GPL*', 'README.lic*', 'COPYRIGHT*', '[Cc]opyright*', 'e[dp]l-v10'] | 199 | licspecs = ['*LICEN[CS]E*', 'COPYING*', '*[Ll]icense*', 'LEGAL*', '[Ll]egal*', '*GPL*', 'README.lic*', 'COPYRIGHT*', '[Cc]opyright*', 'e[dp]l-v10'] |
| 196 | skip_extensions = (".html", ".js", ".json", ".svg", ".ts", ".go", ".sh") | 200 | skip_extensions = (".html", ".js", ".json", ".svg", ".ts", ".go", ".sh") |
| 197 | licfiles = [] | 201 | licfiles = [] |
| 198 | for root, dirs, files in os.walk(srctree): | 202 | for root, dirs, files in os.walk(srctree): |
| 199 | for fn in files: | 203 | # Sort files so that LICENSE is before LICENSE.subcomponent, which is |
| 204 | # meaningful if first_only is set. | ||
| 205 | for fn in sorted(files): | ||
| 200 | if fn.endswith(skip_extensions): | 206 | if fn.endswith(skip_extensions): |
| 201 | continue | 207 | continue |
| 202 | for spec in licspecs: | 208 | for spec in licspecs: |
| @@ -204,6 +210,8 @@ def find_license_files(srctree): | |||
| 204 | fullpath = os.path.join(root, fn) | 210 | fullpath = os.path.join(root, fn) |
| 205 | if not fullpath in licfiles: | 211 | if not fullpath in licfiles: |
| 206 | licfiles.append(fullpath) | 212 | licfiles.append(fullpath) |
| 213 | if first_only: | ||
| 214 | return licfiles | ||
| 207 | 215 | ||
| 208 | return licfiles | 216 | return licfiles |
| 209 | 217 | ||
| @@ -233,8 +241,8 @@ def match_licenses(licfiles, srctree, d): | |||
| 233 | return licenses | 241 | return licenses |
| 234 | 242 | ||
| 235 | 243 | ||
| 236 | def find_licenses(srctree, d): | 244 | def find_licenses(srctree, d, first_only=False): |
| 237 | licfiles = find_license_files(srctree) | 245 | licfiles = find_license_files(srctree, first_only) |
| 238 | licenses = match_licenses(licfiles, srctree, d) | 246 | licenses = match_licenses(licfiles, srctree, d) |
| 239 | 247 | ||
| 240 | # FIXME should we grab at least one source file with a license header and add that too? | 248 | # FIXME should we grab at least one source file with a license header and add that too? |
