diff options
| -rw-r--r-- | meta/classes/license.bbclass | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/meta/classes/license.bbclass b/meta/classes/license.bbclass index 26c297d5b2..1313fdacb7 100644 --- a/meta/classes/license.bbclass +++ b/meta/classes/license.bbclass | |||
| @@ -385,6 +385,7 @@ def find_license_files(d): | |||
| 385 | """ | 385 | """ |
| 386 | import shutil | 386 | import shutil |
| 387 | import oe.license | 387 | import oe.license |
| 388 | from collections import defaultdict, OrderedDict | ||
| 388 | 389 | ||
| 389 | pn = d.getVar('PN', True) | 390 | pn = d.getVar('PN', True) |
| 390 | for package in d.getVar('PACKAGES', True): | 391 | for package in d.getVar('PACKAGES', True): |
| @@ -409,6 +410,8 @@ def find_license_files(d): | |||
| 409 | generic_directory = d.getVar('COMMON_LICENSE_DIR', True) | 410 | generic_directory = d.getVar('COMMON_LICENSE_DIR', True) |
| 410 | # List of basename, path tuples | 411 | # List of basename, path tuples |
| 411 | lic_files_paths = [] | 412 | lic_files_paths = [] |
| 413 | # Entries from LIC_FILES_CHKSUM | ||
| 414 | lic_chksums = {} | ||
| 412 | license_source_dirs = [] | 415 | license_source_dirs = [] |
| 413 | license_source_dirs.append(generic_directory) | 416 | license_source_dirs.append(generic_directory) |
| 414 | try: | 417 | try: |
| @@ -438,7 +441,6 @@ def find_license_files(d): | |||
| 438 | license_source = None | 441 | license_source = None |
| 439 | # If the generic does not exist we need to check to see if there is an SPDX mapping to it, | 442 | # If the generic does not exist we need to check to see if there is an SPDX mapping to it, |
| 440 | # unless NO_GENERIC_LICENSE is set. | 443 | # unless NO_GENERIC_LICENSE is set. |
| 441 | |||
| 442 | for lic_dir in license_source_dirs: | 444 | for lic_dir in license_source_dirs: |
| 443 | if not os.path.isfile(os.path.join(lic_dir, license_type)): | 445 | if not os.path.isfile(os.path.join(lic_dir, license_type)): |
| 444 | if d.getVarFlag('SPDXLICENSEMAP', license_type, True) != None: | 446 | if d.getVarFlag('SPDXLICENSEMAP', license_type, True) != None: |
| @@ -452,6 +454,7 @@ def find_license_files(d): | |||
| 452 | license_source = lic_dir | 454 | license_source = lic_dir |
| 453 | break | 455 | break |
| 454 | 456 | ||
| 457 | non_generic_lic = d.getVarFlag('NO_GENERIC_LICENSE', license_type, True) | ||
| 455 | if spdx_generic and license_source: | 458 | if spdx_generic and license_source: |
| 456 | # we really should copy to generic_ + spdx_generic, however, that ends up messing the manifest | 459 | # we really should copy to generic_ + spdx_generic, however, that ends up messing the manifest |
| 457 | # audit up. This should be fixed in emit_pkgdata (or, we actually got and fix all the recipes) | 460 | # audit up. This should be fixed in emit_pkgdata (or, we actually got and fix all the recipes) |
| @@ -463,13 +466,11 @@ def find_license_files(d): | |||
| 463 | if d.getVarFlag('NO_GENERIC_LICENSE', license_type, True): | 466 | if d.getVarFlag('NO_GENERIC_LICENSE', license_type, True): |
| 464 | bb.warn("%s: %s is a generic license, please don't use NO_GENERIC_LICENSE for it." % (pn, license_type)) | 467 | bb.warn("%s: %s is a generic license, please don't use NO_GENERIC_LICENSE for it." % (pn, license_type)) |
| 465 | 468 | ||
| 466 | elif d.getVarFlag('NO_GENERIC_LICENSE', license_type, True): | 469 | elif non_generic_lic and non_generic_lic in lic_chksums: |
| 467 | # if NO_GENERIC_LICENSE is set, we copy the license files from the fetched source | 470 | # if NO_GENERIC_LICENSE is set, we copy the license files from the fetched source |
| 468 | # of the package rather than the license_source_dirs. | 471 | # of the package rather than the license_source_dirs. |
| 469 | for (basename, path) in lic_files_paths: | 472 | lic_files_paths.append(("generic_" + license_type, |
| 470 | if d.getVarFlag('NO_GENERIC_LICENSE', license_type, True) == basename: | 473 | os.path.join(srcdir, non_generic_lic))) |
| 471 | lic_files_paths.append(("generic_" + license_type, path)) | ||
| 472 | break | ||
| 473 | else: | 474 | else: |
| 474 | # Add explicity avoid of CLOSED license because this isn't generic | 475 | # Add explicity avoid of CLOSED license because this isn't generic |
| 475 | if license_type != 'CLOSED': | 476 | if license_type != 'CLOSED': |
| @@ -492,8 +493,8 @@ def find_license_files(d): | |||
| 492 | except bb.fetch.MalformedUrl: | 493 | except bb.fetch.MalformedUrl: |
| 493 | raise bb.build.FuncFailed("%s: LIC_FILES_CHKSUM contains an invalid URL: %s" % (d.getVar('PF', True), url)) | 494 | raise bb.build.FuncFailed("%s: LIC_FILES_CHKSUM contains an invalid URL: %s" % (d.getVar('PF', True), url)) |
| 494 | # We want the license filename and path | 495 | # We want the license filename and path |
| 495 | srclicfile = os.path.join(srcdir, path) | 496 | chksum = parm['md5'] if 'md5' in parm else parm['sha256'] |
| 496 | lic_files_paths.append((os.path.basename(path), srclicfile)) | 497 | lic_chksums[path] = chksum |
| 497 | 498 | ||
| 498 | v = FindVisitor() | 499 | v = FindVisitor() |
| 499 | try: | 500 | try: |
| @@ -503,6 +504,19 @@ def find_license_files(d): | |||
| 503 | except SyntaxError: | 504 | except SyntaxError: |
| 504 | bb.warn("%s: Failed to parse it's LICENSE field." % (d.getVar('PF', True))) | 505 | bb.warn("%s: Failed to parse it's LICENSE field." % (d.getVar('PF', True))) |
| 505 | 506 | ||
| 507 | # Add files from LIC_FILES_CHKSUM to list of license files | ||
| 508 | lic_chksum_paths = defaultdict(OrderedDict) | ||
| 509 | for path, chksum in lic_chksums.items(): | ||
| 510 | lic_chksum_paths[os.path.basename(path)][chksum] = os.path.join(srcdir, path) | ||
| 511 | for basename, files in lic_chksum_paths.items(): | ||
| 512 | if len(files) == 1: | ||
| 513 | lic_files_paths.append((basename, list(files.values())[0])) | ||
| 514 | else: | ||
| 515 | # If there are multiple different license files with identical | ||
| 516 | # basenames we rename them to <file>.0, <file>.1, ... | ||
| 517 | for i, path in enumerate(files.values()): | ||
| 518 | lic_files_paths.append(("%s.%d" % (basename, i), path)) | ||
| 519 | |||
| 506 | return lic_files_paths | 520 | return lic_files_paths |
| 507 | 521 | ||
| 508 | def return_spdx(d, license): | 522 | def return_spdx(d, license): |
