Advertisement
RobertBerger

license-exists

Aug 23rd, 2022
291
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.19 KB | None | 0 0
  1. def find_license_files(d):
  2. """
  3. Creates list of files used in LIC_FILES_CHKSUM and generic LICENSE files.
  4. """
  5. import shutil
  6. import oe.license
  7. from collections import defaultdict, OrderedDict
  8.  
  9. # All the license files for the package
  10. lic_files = d.getVar('LIC_FILES_CHKSUM') or ""
  11. pn = d.getVar('PN')
  12. # The license files are located in S/LIC_FILE_CHECKSUM.
  13. srcdir = d.getVar('S')
  14. # Directory we store the generic licenses as set in the distro configuration
  15. generic_directory = d.getVar('COMMON_LICENSE_DIR')
  16. # List of basename, path tuples
  17. lic_files_paths = []
  18. # hash for keep track generic lics mappings
  19. non_generic_lics = {}
  20. # Entries from LIC_FILES_CHKSUM
  21. lic_chksums = {}
  22. license_source_dirs = []
  23. license_source_dirs.append(generic_directory)
  24. try:
  25. additional_lic_dirs = d.getVar('LICENSE_PATH').split()
  26. for lic_dir in additional_lic_dirs:
  27. license_source_dirs.append(lic_dir)
  28. except:
  29. pass
  30.  
  31. class FindVisitor(oe.license.LicenseVisitor):
  32. def visit_Str(self, node):
  33. #
  34. # Until I figure out what to do with
  35. # the two modifiers I support (or greater = +
  36. # and "with exceptions" being *
  37. # we'll just strip out the modifier and put
  38. # the base license.
  39. find_license(node.s.replace("+", "").replace("*", ""))
  40. self.generic_visit(node)
  41.  
  42. def visit_Constant(self, node):
  43. find_license(node.value.replace("+", "").replace("*", ""))
  44. self.generic_visit(node)
  45.  
  46. def find_license(license_type):
  47. try:
  48. bb.utils.mkdirhier(gen_lic_dest)
  49. except:
  50. pass
  51. spdx_generic = None
  52. license_source = None
  53. # If the generic does not exist we need to check to see if there is an SPDX mapping to it,
  54. # unless NO_GENERIC_LICENSE is set.
  55. for lic_dir in license_source_dirs:
  56. if not os.path.isfile(os.path.join(lic_dir, license_type)):
  57. if d.getVarFlag('SPDXLICENSEMAP', license_type) != None:
  58. # Great, there is an SPDXLICENSEMAP. We can copy!
  59. bb.debug(1, "We need to use a SPDXLICENSEMAP for %s" % (license_type))
  60. spdx_generic = d.getVarFlag('SPDXLICENSEMAP', license_type)
  61. license_source = lic_dir
  62. break
  63. elif os.path.isfile(os.path.join(lic_dir, license_type)):
  64. spdx_generic = license_type
  65. license_source = lic_dir
  66. break
  67.  
  68. non_generic_lic = d.getVarFlag('NO_GENERIC_LICENSE', license_type)
  69. if spdx_generic and license_source:
  70. # we really should copy to generic_ + spdx_generic, however, that ends up messing the manifest
  71. # audit up. This should be fixed in emit_pkgdata (or, we actually got and fix all the recipes)
  72.  
  73. lic_files_paths.append(("generic_" + license_type, os.path.join(license_source, spdx_generic),
  74. None, None))
  75.  
  76. # The user may attempt to use NO_GENERIC_LICENSE for a generic license which doesn't make sense
  77. # and should not be allowed, warn the user in this case.
  78. elif os.path.isfile(os.path.join(lic_dir, license_type)):
  79. spdx_generic = license_type
  80. license_source = lic_dir
  81. break
  82.  
  83. non_generic_lic = d.getVarFlag('NO_GENERIC_LICENSE', license_type)
  84. if spdx_generic and license_source:
  85. # we really should copy to generic_ + spdx_generic, however, that ends up messing the manifest
  86. # audit up. This should be fixed in emit_pkgdata (or, we actually got and fix all the recipes)
  87.  
  88. lic_files_paths.append(("generic_" + license_type, os.path.join(license_source, spdx_generic),
  89. None, None))
  90.  
  91. # The user may attempt to use NO_GENERIC_LICENSE for a generic license which doesn't make sense
  92. # and should not be allowed, warn the user in this case.
  93. if d.getVarFlag('NO_GENERIC_LICENSE', license_type):
  94. oe.qa.handle_error("license-no-generic",
  95. "%s: %s is a generic license, please don't use NO_GENERIC_LICENSE for it." % (pn, license_type), d)
  96.  
  97. elif non_generic_lic and non_generic_lic in lic_chksums:
  98. # if NO_GENERIC_LICENSE is set, we copy the license files from the fetched source
  99. # of the package rather than the license_source_dirs.
  100. lic_files_paths.append(("generic_" + license_type,
  101. os.path.join(srcdir, non_generic_lic), None, None))
  102. non_generic_lics[non_generic_lic] = license_type
  103. else:
  104. # Explicitly avoid the CLOSED license because this isn't generic
  105. if license_type != 'CLOSED':
  106. # And here is where we warn people that their licenses are lousy
  107. oe.qa.handle_error("license-exists",
  108. "%s: No generic license file exists for: %s in any provider" % (pn, license_type), d)
  109. pass
  110.  
  111. ...
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement