diff options
Diffstat (limited to 'import-layers/yocto-poky/meta/classes/license.bbclass')
-rw-r--r-- | import-layers/yocto-poky/meta/classes/license.bbclass | 84 |
1 files changed, 47 insertions, 37 deletions
diff --git a/import-layers/yocto-poky/meta/classes/license.bbclass b/import-layers/yocto-poky/meta/classes/license.bbclass index 43944e6ee..da4fc3e1d 100644 --- a/import-layers/yocto-poky/meta/classes/license.bbclass +++ b/import-layers/yocto-poky/meta/classes/license.bbclass @@ -181,8 +181,10 @@ def license_deployed_manifest(d): key,val = line.split(": ", 1) man_dic[dep][key] = val[:-1] - image_license_manifest = os.path.join(d.getVar('LICENSE_DIRECTORY', True), - d.getVar('IMAGE_NAME', True), 'image_license.manifest') + lic_manifest_dir = os.path.join(d.getVar('LICENSE_DIRECTORY', True), + d.getVar('IMAGE_NAME', True)) + bb.utils.mkdirhier(lic_manifest_dir) + image_license_manifest = os.path.join(lic_manifest_dir, 'image_license.manifest') write_license_files(d, image_license_manifest, man_dic) def get_deployed_dependencies(d): @@ -198,7 +200,7 @@ def get_deployed_dependencies(d): # it might contain the bootloader. taskdata = d.getVar("BB_TASKDEPDATA", False) depends = list(set([dep[0] for dep - in taskdata.itervalues() + in list(taskdata.values()) if not dep[0].endswith("-native")])) extra_depends = d.getVar("EXTRA_IMAGEDEPENDS", True) boot_depends = get_boot_dependencies(d) @@ -259,7 +261,7 @@ def get_boot_dependencies(d): depends.append(dep) # We need to search for the provider of the dependency else: - for taskdep in taskdepdata.itervalues(): + for taskdep in taskdepdata.values(): # The fifth field contains what the task provides if dep in taskdep[4]: info_file = os.path.join( @@ -340,6 +342,7 @@ def add_package_and_files(d): def copy_license_files(lic_files_paths, destdir): import shutil + import errno bb.utils.mkdirhier(destdir) for (basename, path) in lic_files_paths: @@ -348,12 +351,21 @@ def copy_license_files(lic_files_paths, destdir): dst = os.path.join(destdir, basename) if os.path.exists(dst): os.remove(dst) - if os.access(src, os.W_OK) and (os.stat(src).st_dev == os.stat(destdir).st_dev): - os.link(src, dst) + canlink = os.access(src, os.W_OK) and (os.stat(src).st_dev == os.stat(destdir).st_dev) + if canlink: try: - os.chown(dst,0,0) + os.link(src, dst) + except OSError as err: + if err.errno == errno.EXDEV: + # Copy license files if hard-link is not possible even if st_dev is the + # same on source and destination (docker container with device-mapper?) + canlink = False + else: + raise + try: + if canlink: + os.chown(dst,0,0) except OSError as err: - import errno if err.errno in (errno.EPERM, errno.EINVAL): # Suppress "Operation not permitted" error, as # sometimes this function is not executed under pseudo. @@ -362,7 +374,7 @@ def copy_license_files(lic_files_paths, destdir): pass else: raise - else: + if not canlink: shutil.copyfile(src, dst) except Exception as e: bb.warn("Could not copy license file %s to %s: %s" % (src, dst, e)) @@ -373,21 +385,8 @@ def find_license_files(d): """ import shutil import oe.license + from collections import defaultdict, OrderedDict - pn = d.getVar('PN', True) - for package in d.getVar('PACKAGES', True): - if d.getVar('LICENSE_' + package, True): - license_types = license_types + ' & ' + \ - d.getVar('LICENSE_' + package, True) - - #If we get here with no license types, then that means we have a recipe - #level license. If so, we grab only those. - try: - license_types - except NameError: - # All the license types at the recipe level - license_types = d.getVar('LICENSE', True) - # All the license files for the package lic_files = d.getVar('LIC_FILES_CHKSUM', True) pn = d.getVar('PN', True) @@ -397,6 +396,8 @@ def find_license_files(d): generic_directory = d.getVar('COMMON_LICENSE_DIR', True) # List of basename, path tuples lic_files_paths = [] + # Entries from LIC_FILES_CHKSUM + lic_chksums = {} license_source_dirs = [] license_source_dirs.append(generic_directory) try: @@ -426,7 +427,6 @@ def find_license_files(d): license_source = None # If the generic does not exist we need to check to see if there is an SPDX mapping to it, # unless NO_GENERIC_LICENSE is set. - for lic_dir in license_source_dirs: if not os.path.isfile(os.path.join(lic_dir, license_type)): if d.getVarFlag('SPDXLICENSEMAP', license_type, True) != None: @@ -440,6 +440,7 @@ def find_license_files(d): license_source = lic_dir break + non_generic_lic = d.getVarFlag('NO_GENERIC_LICENSE', license_type, True) if spdx_generic and license_source: # we really should copy to generic_ + spdx_generic, however, that ends up messing the manifest # audit up. This should be fixed in emit_pkgdata (or, we actually got and fix all the recipes) @@ -451,13 +452,11 @@ def find_license_files(d): if d.getVarFlag('NO_GENERIC_LICENSE', license_type, True): bb.warn("%s: %s is a generic license, please don't use NO_GENERIC_LICENSE for it." % (pn, license_type)) - elif d.getVarFlag('NO_GENERIC_LICENSE', license_type, True): + elif non_generic_lic and non_generic_lic in lic_chksums: # if NO_GENERIC_LICENSE is set, we copy the license files from the fetched source # of the package rather than the license_source_dirs. - for (basename, path) in lic_files_paths: - if d.getVarFlag('NO_GENERIC_LICENSE', license_type, True) == basename: - lic_files_paths.append(("generic_" + license_type, path)) - break + lic_files_paths.append(("generic_" + license_type, + os.path.join(srcdir, non_generic_lic))) else: # Add explicity avoid of CLOSED license because this isn't generic if license_type != 'CLOSED': @@ -466,7 +465,7 @@ def find_license_files(d): pass if not generic_directory: - raise bb.build.FuncFailed("COMMON_LICENSE_DIR is unset. Please set this in your distro config") + bb.fatal("COMMON_LICENSE_DIR is unset. Please set this in your distro config") if not lic_files: # No recipe should have an invalid license file. This is checked else @@ -478,19 +477,32 @@ def find_license_files(d): try: (type, host, path, user, pswd, parm) = bb.fetch.decodeurl(url) except bb.fetch.MalformedUrl: - raise bb.build.FuncFailed("%s: LIC_FILES_CHKSUM contains an invalid URL: %s" % (d.getVar('PF', True), url)) + bb.fatal("%s: LIC_FILES_CHKSUM contains an invalid URL: %s" % (d.getVar('PF', True), url)) # We want the license filename and path - srclicfile = os.path.join(srcdir, path) - lic_files_paths.append((os.path.basename(path), srclicfile)) + chksum = parm['md5'] if 'md5' in parm else parm['sha256'] + lic_chksums[path] = chksum v = FindVisitor() try: - v.visit_string(license_types) + v.visit_string(d.getVar('LICENSE', True)) except oe.license.InvalidLicense as exc: bb.fatal('%s: %s' % (d.getVar('PF', True), exc)) except SyntaxError: bb.warn("%s: Failed to parse it's LICENSE field." % (d.getVar('PF', True))) + # Add files from LIC_FILES_CHKSUM to list of license files + lic_chksum_paths = defaultdict(OrderedDict) + for path, chksum in lic_chksums.items(): + lic_chksum_paths[os.path.basename(path)][chksum] = os.path.join(srcdir, path) + for basename, files in lic_chksum_paths.items(): + if len(files) == 1: + lic_files_paths.append((basename, list(files.values())[0])) + else: + # If there are multiple different license files with identical + # basenames we rename them to <file>.0, <file>.1, ... + for i, path in enumerate(files.values()): + lic_files_paths.append(("%s.%d" % (basename, i), path)) + return lic_files_paths def return_spdx(d, license): @@ -633,7 +645,7 @@ def check_license_format(d): licenses = d.getVar('LICENSE', True) from oe.license import license_operator, license_operator_chars, license_pattern - elements = filter(lambda x: x.strip(), license_operator.split(licenses)) + elements = list(filter(lambda x: x.strip(), license_operator.split(licenses))) for pos, element in enumerate(elements): if license_pattern.match(element): if pos > 0 and license_pattern.match(elements[pos - 1]): @@ -656,8 +668,6 @@ do_rootfs[recrdeptask] += "do_populate_lic" IMAGE_POSTPROCESS_COMMAND_prepend = "write_deploy_manifest; " do_image[recrdeptask] += "do_populate_lic" -do_populate_lic_setscene[dirs] = "${LICSSTATEDIR}/${PN}" -do_populate_lic_setscene[cleandirs] = "${LICSSTATEDIR}" python do_populate_lic_setscene () { sstate_setscene(d) } |