summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--meta/classes/license.bbclass34
1 files changed, 23 insertions, 11 deletions
diff --git a/meta/classes/license.bbclass b/meta/classes/license.bbclass
index 44467d09bf..9923aac4ec 100644
--- a/meta/classes/license.bbclass
+++ b/meta/classes/license.bbclass
@@ -345,7 +345,7 @@ def copy_license_files(lic_files_paths, destdir):
345 import errno 345 import errno
346 346
347 bb.utils.mkdirhier(destdir) 347 bb.utils.mkdirhier(destdir)
348 for (basename, path) in lic_files_paths: 348 for (basename, path, beginline, endline) in lic_files_paths:
349 try: 349 try:
350 src = path 350 src = path
351 dst = os.path.join(destdir, basename) 351 dst = os.path.join(destdir, basename)
@@ -353,7 +353,7 @@ def copy_license_files(lic_files_paths, destdir):
353 os.remove(dst) 353 os.remove(dst)
354 if os.path.islink(src): 354 if os.path.islink(src):
355 src = os.path.realpath(src) 355 src = os.path.realpath(src)
356 canlink = os.access(src, os.W_OK) and (os.stat(src).st_dev == os.stat(destdir).st_dev) 356 canlink = os.access(src, os.W_OK) and (os.stat(src).st_dev == os.stat(destdir).st_dev) and beginline is None and endline is None
357 if canlink: 357 if canlink:
358 try: 358 try:
359 os.link(src, dst) 359 os.link(src, dst)
@@ -377,7 +377,15 @@ def copy_license_files(lic_files_paths, destdir):
377 else: 377 else:
378 raise 378 raise
379 if not canlink: 379 if not canlink:
380 shutil.copyfile(src, dst) 380 begin_idx = int(beginline)-1 if beginline is not None else None
381 end_idx = int(endline) if endline is not None else None
382 if begin_idx is None and end_idx is None:
383 shutil.copyfile(src, dst)
384 else:
385 with open(src, 'r') as src_f:
386 with open(dst, 'w') as dst_f:
387 dst_f.write(''.join(src_f.readlines()[begin_idx:end_idx]))
388
381 except Exception as e: 389 except Exception as e:
382 bb.warn("Could not copy license file %s to %s: %s" % (src, dst, e)) 390 bb.warn("Could not copy license file %s to %s: %s" % (src, dst, e))
383 391
@@ -447,7 +455,8 @@ def find_license_files(d):
447 # we really should copy to generic_ + spdx_generic, however, that ends up messing the manifest 455 # we really should copy to generic_ + spdx_generic, however, that ends up messing the manifest
448 # audit up. This should be fixed in emit_pkgdata (or, we actually got and fix all the recipes) 456 # audit up. This should be fixed in emit_pkgdata (or, we actually got and fix all the recipes)
449 457
450 lic_files_paths.append(("generic_" + license_type, os.path.join(license_source, spdx_generic))) 458 lic_files_paths.append(("generic_" + license_type, os.path.join(license_source, spdx_generic),
459 None, None))
451 460
452 # The user may attempt to use NO_GENERIC_LICENSE for a generic license which doesn't make sense 461 # The user may attempt to use NO_GENERIC_LICENSE for a generic license which doesn't make sense
453 # and should not be allowed, warn the user in this case. 462 # and should not be allowed, warn the user in this case.
@@ -458,7 +467,7 @@ def find_license_files(d):
458 # if NO_GENERIC_LICENSE is set, we copy the license files from the fetched source 467 # if NO_GENERIC_LICENSE is set, we copy the license files from the fetched source
459 # of the package rather than the license_source_dirs. 468 # of the package rather than the license_source_dirs.
460 lic_files_paths.append(("generic_" + license_type, 469 lic_files_paths.append(("generic_" + license_type,
461 os.path.join(srcdir, non_generic_lic))) 470 os.path.join(srcdir, non_generic_lic), None, None))
462 else: 471 else:
463 # Add explicity avoid of CLOSED license because this isn't generic 472 # Add explicity avoid of CLOSED license because this isn't generic
464 if license_type != 'CLOSED': 473 if license_type != 'CLOSED':
@@ -476,7 +485,9 @@ def find_license_files(d):
476 bb.fatal("%s: LIC_FILES_CHKSUM contains an invalid URL: %s" % (d.getVar('PF'), url)) 485 bb.fatal("%s: LIC_FILES_CHKSUM contains an invalid URL: %s" % (d.getVar('PF'), url))
477 # We want the license filename and path 486 # We want the license filename and path
478 chksum = parm['md5'] if 'md5' in parm else parm['sha256'] 487 chksum = parm['md5'] if 'md5' in parm else parm['sha256']
479 lic_chksums[path] = chksum 488 beginline = parm.get('beginline')
489 endline = parm.get('endline')
490 lic_chksums[path] = (chksum, beginline, endline)
480 491
481 v = FindVisitor() 492 v = FindVisitor()
482 try: 493 try:
@@ -488,16 +499,17 @@ def find_license_files(d):
488 499
489 # Add files from LIC_FILES_CHKSUM to list of license files 500 # Add files from LIC_FILES_CHKSUM to list of license files
490 lic_chksum_paths = defaultdict(OrderedDict) 501 lic_chksum_paths = defaultdict(OrderedDict)
491 for path, chksum in lic_chksums.items(): 502 for path, data in lic_chksums.items():
492 lic_chksum_paths[os.path.basename(path)][chksum] = os.path.join(srcdir, path) 503 lic_chksum_paths[os.path.basename(path)][data] = (os.path.join(srcdir, path), data[1], data[2])
493 for basename, files in lic_chksum_paths.items(): 504 for basename, files in lic_chksum_paths.items():
494 if len(files) == 1: 505 if len(files) == 1:
495 lic_files_paths.append((basename, list(files.values())[0])) 506 data = list(files.values())[0]
507 lic_files_paths.append(tuple([basename] + list(data)))
496 else: 508 else:
497 # If there are multiple different license files with identical 509 # If there are multiple different license files with identical
498 # basenames we rename them to <file>.0, <file>.1, ... 510 # basenames we rename them to <file>.0, <file>.1, ...
499 for i, path in enumerate(files.values()): 511 for i, data in enumerate(files.values()):
500 lic_files_paths.append(("%s.%d" % (basename, i), path)) 512 lic_files_paths.append(tuple(["%s.%d" % (basename, i)] + list(data)))
501 513
502 return lic_files_paths 514 return lic_files_paths
503 515