diff options
| author | Christian Lindeberg <christian.lindeberg@axis.com> | 2025-09-02 16:06:45 +0200 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2025-09-08 18:02:39 +0100 |
| commit | 7cf52b24a5a105a5933e6d1c38678dfe432fc5d9 (patch) | |
| tree | 48dea94b373a55931e47a90537a3ecb4e8beae40 | |
| parent | 39d5df91edeef4cc0a87a60ddb42474c5003d38b (diff) | |
| download | poky-7cf52b24a5a105a5933e6d1c38678dfe432fc5d9.tar.gz | |
oe/license_finder: Add find_licenses_up function
Add a function for finding licenses in a directory or upwards but not
above a top directory.
(From OE-Core rev: c5c3f7397e62e6e4be6b6fe611317a2f5f853a04)
Signed-off-by: Christian Lindeberg <christian.lindeberg@axis.com>
Signed-off-by: Mathieu Dubois-Briand <mathieu.dubois-briand@bootlin.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
| -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) | ||
