summaryrefslogtreecommitdiffstats
path: root/meta/classes/license.bbclass
diff options
context:
space:
mode:
authorMarkus Lehtonen <markus.lehtonen@linux.intel.com>2016-08-05 13:23:52 +0300
committerRichard Purdie <richard.purdie@linuxfoundation.org>2016-08-10 10:46:32 +0100
commita48fea275b08ff3d3dfc9a928aeb04768db35873 (patch)
treea3dd7d5735ba0cab24ad6b7f87cbcfbfe5aac6ed /meta/classes/license.bbclass
parentda72327ab03cbbb72ce999a167e7e3b4b4aa736a (diff)
downloadpoky-a48fea275b08ff3d3dfc9a928aeb04768db35873.tar.gz
license: improve handling of license files with identical basenames
Previously, find_license_files() in license.bbclass just blindly assumed that all different licenses specified in LIC_FILES_CHKSUM have unique filenames. As a consequence, only the last one of these similarly named license files was copied and the rest were "lost". This patch changes the behavior so that all license files get copied. However, if multiple identically named files are found, they are renamed to <file>.0, <file>.1 etc. The patch also changes the handling of NO_GENERIC_LICENSE slightly. Previously, only basenames of NO_GENERIC_LICENSE and LIC_FILES_CHKSUM were compared when searching for the correct license file. After this patch NO_GENERIC_LICENSE must have the full path, matching what is specified in LIC_FILES_CHKSUM. This is required in order to be able to handle identical filenames (basenames) consistently. For example, if you have: LICENSE = "my-custom-license" LIC_FILES_CHKSUM = "file://src/LICENCE;md5=d41d8cd98f00b204e9800998ecf8427e" you must specify: NO_GENERIC_LICENSE[my-custom-license] = "src/LICENCE" [YOCTO #9663] (From OE-Core rev: d5e1375884e509ec745bac43f1f7f7950f62f280) Signed-off-by: Markus Lehtonen <markus.lehtonen@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
Diffstat (limited to 'meta/classes/license.bbclass')
-rw-r--r--meta/classes/license.bbclass30
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
508def return_spdx(d, license): 522def return_spdx(d, license):