From 9d57b53169bc60b281510c49e54123941a17a8f5 Mon Sep 17 00:00:00 2001 From: Ross Burton Date: Fri, 27 Jun 2025 14:48:46 +0100 Subject: [PATCH] oe/licenses: move tidy_licenses from recipetool This function, to tidy a license string, is useful outside of recipetool so move it to oe.license. Signed-off-by: Ross Burton Signed-off-by: Richard Purdie --- meta/lib/oe/license.py | 15 +++++++++++++++ scripts/lib/recipetool/create.py | 11 +---------- 2 files changed, 16 insertions(+), 10 deletions(-) diff --git a/meta/lib/oe/license.py b/meta/lib/oe/license.py index 6f882c3812..6e55fa1e7f 100644 --- a/meta/lib/oe/license.py +++ b/meta/lib/oe/license.py @@ -462,3 +462,18 @@ def skip_incompatible_package_licenses(d, pkgs): skipped_pkgs[pkg] = incompatible_lic return skipped_pkgs + +def tidy_licenses(value): + """ + Flat, split and sort licenses. + """ + from oe.license import flattened_licenses + + def _choose(a, b): + str_a, str_b = sorted((" & ".join(a), " & ".join(b)), key=str.casefold) + return ["(%s | %s)" % (str_a, str_b)] + + if not isinstance(value, str): + value = " & ".join(value) + + return sorted(list(set(flattened_licenses(value, _choose))), key=str.casefold) diff --git a/scripts/lib/recipetool/create.py b/scripts/lib/recipetool/create.py index 5d7fcbbb98..ef0ba974a9 100644 --- a/scripts/lib/recipetool/create.py +++ b/scripts/lib/recipetool/create.py @@ -18,6 +18,7 @@ from urllib.parse import urlparse, urldefrag, urlsplit import hashlib import bb.fetch2 logger = logging.getLogger('recipetool') +from oe.license import tidy_licenses from oe.license_finder import find_licenses tinfoil = None @@ -950,16 +951,6 @@ def fixup_license(value): return '(' + value + ')' return value -def tidy_licenses(value): - """Flat, split and sort licenses""" - from oe.license import flattened_licenses - def _choose(a, b): - str_a, str_b = sorted((" & ".join(a), " & ".join(b)), key=str.casefold) - return ["(%s | %s)" % (str_a, str_b)] - if not isinstance(value, str): - value = " & ".join(value) - return sorted(list(set(flattened_licenses(value, _choose))), key=str.casefold) - def handle_license_vars(srctree, lines_before, handled, extravalues, d): lichandled = [x for x in handled if x[0] == 'license'] if lichandled: -- 2.47.3