Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def find_license_files(d):
- """
- Creates list of files used in LIC_FILES_CHKSUM and generic LICENSE files.
- """
- import shutil
- import oe.license
- from collections import defaultdict, OrderedDict
- # All the license files for the package
- lic_files = d.getVar('LIC_FILES_CHKSUM') or ""
- pn = d.getVar('PN')
- # The license files are located in S/LIC_FILE_CHECKSUM.
- srcdir = d.getVar('S')
- # Directory we store the generic licenses as set in the distro configuration
- generic_directory = d.getVar('COMMON_LICENSE_DIR')
- # List of basename, path tuples
- lic_files_paths = []
- # hash for keep track generic lics mappings
- non_generic_lics = {}
- # Entries from LIC_FILES_CHKSUM
- lic_chksums = {}
- license_source_dirs = []
- license_source_dirs.append(generic_directory)
- try:
- additional_lic_dirs = d.getVar('LICENSE_PATH').split()
- for lic_dir in additional_lic_dirs:
- license_source_dirs.append(lic_dir)
- except:
- pass
- class FindVisitor(oe.license.LicenseVisitor):
- def visit_Str(self, node):
- #
- # Until I figure out what to do with
- # the two modifiers I support (or greater = +
- # and "with exceptions" being *
- # we'll just strip out the modifier and put
- # the base license.
- find_license(node.s.replace("+", "").replace("*", ""))
- self.generic_visit(node)
- def visit_Constant(self, node):
- find_license(node.value.replace("+", "").replace("*", ""))
- self.generic_visit(node)
- def find_license(license_type):
- try:
- bb.utils.mkdirhier(gen_lic_dest)
- except:
- pass
- spdx_generic = None
- 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) != None:
- # Great, there is an SPDXLICENSEMAP. We can copy!
- bb.debug(1, "We need to use a SPDXLICENSEMAP for %s" % (license_type))
- spdx_generic = d.getVarFlag('SPDXLICENSEMAP', license_type)
- license_source = lic_dir
- break
- elif os.path.isfile(os.path.join(lic_dir, license_type)):
- spdx_generic = license_type
- license_source = lic_dir
- break
- non_generic_lic = d.getVarFlag('NO_GENERIC_LICENSE', license_type)
- 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)
- lic_files_paths.append(("generic_" + license_type, os.path.join(license_source, spdx_generic),
- None, None))
- # The user may attempt to use NO_GENERIC_LICENSE for a generic license which doesn't make sense
- # and should not be allowed, warn the user in this case.
- elif os.path.isfile(os.path.join(lic_dir, license_type)):
- spdx_generic = license_type
- license_source = lic_dir
- break
- non_generic_lic = d.getVarFlag('NO_GENERIC_LICENSE', license_type)
- 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)
- lic_files_paths.append(("generic_" + license_type, os.path.join(license_source, spdx_generic),
- None, None))
- # The user may attempt to use NO_GENERIC_LICENSE for a generic license which doesn't make sense
- # and should not be allowed, warn the user in this case.
- if d.getVarFlag('NO_GENERIC_LICENSE', license_type):
- oe.qa.handle_error("license-no-generic",
- "%s: %s is a generic license, please don't use NO_GENERIC_LICENSE for it." % (pn, license_type), d)
- 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.
- lic_files_paths.append(("generic_" + license_type,
- os.path.join(srcdir, non_generic_lic), None, None))
- non_generic_lics[non_generic_lic] = license_type
- else:
- # Explicitly avoid the CLOSED license because this isn't generic
- if license_type != 'CLOSED':
- # And here is where we warn people that their licenses are lousy
- oe.qa.handle_error("license-exists",
- "%s: No generic license file exists for: %s in any provider" % (pn, license_type), d)
- pass
- ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement