summaryrefslogtreecommitdiffstats
path: root/meta
diff options
context:
space:
mode:
Diffstat (limited to 'meta')
-rw-r--r--meta/classes/license.bbclass163
1 files changed, 82 insertions, 81 deletions
diff --git a/meta/classes/license.bbclass b/meta/classes/license.bbclass
index d9409a90ba..975867d241 100644
--- a/meta/classes/license.bbclass
+++ b/meta/classes/license.bbclass
@@ -25,87 +25,88 @@ python write_package_manifest() {
25 'w+').write(image_list_installed_packages(d)) 25 'w+').write(image_list_installed_packages(d))
26} 26}
27 27
28license_create_manifest() { 28python license_create_manifest() {
29 # Test if BUILD_IMAGES_FROM_FEEDS is defined in env 29 import re
30 if [ -n "${BUILD_IMAGES_FROM_FEEDS}" ]; then 30 import oe.packagedata
31 exit 0 31
32 fi 32 build_images_from_feeds = d.getVar('BUILD_IMAGES_FROM_FEEDS', True)
33 33 if build_images_from_feeds == "1":
34 INSTALLED_PKGS=`cat ${LICENSE_DIRECTORY}/${IMAGE_NAME}/package.manifest` 34 return 0
35 LICENSE_MANIFEST="${LICENSE_DIRECTORY}/${IMAGE_NAME}/license.manifest" 35
36 # remove existing license.manifest file 36 pkg_dic = {}
37 if [ -f ${LICENSE_MANIFEST} ]; then 37 package_manifest = os.path.join(d.getVar('LICENSE_DIRECTORY', True),
38 rm ${LICENSE_MANIFEST} 38 d.getVar('IMAGE_NAME', True), 'package.manifest')
39 fi 39 with open(package_manifest, "r") as package_file:
40 touch ${LICENSE_MANIFEST} 40 pkg_list = package_file.read().split()
41 for pkg in ${INSTALLED_PKGS}; do 41 for pkg in pkg_list:
42 filename=`ls ${PKGDATA_DIR}/runtime-reverse/${pkg}| head -1` 42 pkg_info = os.path.join(d.getVar('PKGDATA_DIR', True),
43 pkged_pn="$(sed -n 's/^PN: //p' ${filename})" 43 'runtime-reverse', pkg)
44 44 pkg_name = os.path.basename(os.readlink(pkg_info))
45 # check to see if the package name exists in the manifest. if so, bail. 45
46 if grep -q "^PACKAGE NAME: ${pkg}" ${LICENSE_MANIFEST}; then 46 pkg_dic[pkg_name] = oe.packagedata.read_pkgdatafile(pkg_info)
47 continue 47 if not "LICENSE" in pkg_dic[pkg_name].keys():
48 fi 48 pkg_lic_name = "LICENSE_" + pkg_name
49 49 pkg_dic[pkg_name]["LICENSE"] = pkg_dic[pkg_name][pkg_lic_name]
50 pkged_pv="$(sed -n 's/^PV: //p' ${filename})" 50
51 pkged_name="$(basename $(readlink ${filename}))" 51 license_manifest = os.path.join(d.getVar('LICENSE_DIRECTORY', True),
52 pkged_lic="$(sed -n "/^LICENSE_${pkged_name}: /{ s/^LICENSE_${pkged_name}: //; p }" ${filename})" 52 d.getVar('IMAGE_NAME', True), 'license.manifest')
53 pkged_size="$(sed -n "/^PKGSIZE_${pkged_name}: /{ s/^PKGSIZE_${pkged_name}: //; p }" ${filename})" 53 with open(license_manifest, "w") as license_file:
54 if [ -z "${pkged_lic}" ]; then 54 for pkg in sorted(pkg_dic):
55 # fallback checking value of LICENSE 55 license_file.write("PACKAGE NAME: %s\n" % pkg)
56 pkged_lic="$(sed -n "/^LICENSE: /{ s/^LICENSE: //; p }" ${filename})" 56 license_file.write("PACKAGE VERSION: %s\n" % pkg_dic[pkg]["PV"])
57 fi 57 license_file.write("RECIPE NAME: %s\n" % pkg_dic[pkg]["PN"])
58 58 license_file.write("LICENSE: %s\n\n" % pkg_dic[pkg]["LICENSE"])
59 echo "PACKAGE NAME:" ${pkg} >> ${LICENSE_MANIFEST} 59
60 echo "PACKAGE VERSION:" ${pkged_pv} >> ${LICENSE_MANIFEST} 60 # If the package doesn't contain any file, that is, its size is 0, the license
61 echo "RECIPE NAME:" ${pkged_pn} >> ${LICENSE_MANIFEST} 61 # isn't relevant as far as the final image is concerned. So doing license check
62 echo "LICENSE:" ${pkged_lic} >> ${LICENSE_MANIFEST} 62 # doesn't make much sense, skip it.
63 echo "" >> ${LICENSE_MANIFEST} 63 if pkg_dic[pkg]["PKGSIZE_%s" % pkg] == "0":
64 64 continue
65 # If the package doesn't contain any file, that is, its size is 0, the license 65
66 # isn't relevant as far as the final image is concerned. So doing license check 66 licenses = re.sub('[|&()*]', '', pkg_dic[pkg]["LICENSE"])
67 # doesn't make much sense, skip it. 67 licenses = re.sub(' *', ' ', licenses)
68 if [ "$pkged_size" = "0" ]; then 68 for lic in licenses.split():
69 continue 69 lic_file = os.path.join(d.getVar('LICENSE_DIRECTORY', True),
70 fi 70 pkg_dic[pkg]["PN"], "generic_%s" %
71 71 re.sub('\+', '', lic))
72 lics="$(echo ${pkged_lic} | sed "s/[|&()*]/ /g" | sed "s/ */ /g" )" 72 if not os.path.exists(lic_file):
73 for lic in ${lics}; do 73 bb.warn("The license listed %s was not in the "\
74 # to reference a license file trim trailing + symbol 74 "licenses collected for recipe %s"
75 if ! [ -e "${LICENSE_DIRECTORY}/${pkged_pn}/generic_${lic%+}" ]; then 75 % (lic, pkg_dic[pkg]["PN"]))
76 bbwarn "The license listed ${lic} was not in the licenses collected for ${pkged_pn}" 76
77 fi 77 # Two options here:
78 done 78 # - Just copy the manifest
79 done 79 # - Copy the manifest and the license directories
80 80 # With both options set we see a .5 M increase in core-image-minimal
81 # Two options here: 81 copy_lic_manifest = d.getVar('COPY_LIC_MANIFEST', True)
82 # - Just copy the manifest 82 copy_lic_dirs = d.getVar('COPY_LIC_DIRS', True)
83 # - Copy the manifest and the license directories 83 if copy_lic_manifest == "1":
84 # With both options set we see a .5 M increase in core-image-minimal 84 rootfs_license_dir = os.path.join(d.getVar('IMAGE_ROOTFS', 'True'),
85 if [ "${COPY_LIC_MANIFEST}" = "1" ]; then 85 'usr', 'share', 'common-licenses')
86 mkdir -p ${IMAGE_ROOTFS}/usr/share/common-licenses/ 86 os.makedirs(rootfs_license_dir)
87 cp ${LICENSE_MANIFEST} ${IMAGE_ROOTFS}/usr/share/common-licenses/license.manifest 87 rootfs_license_manifest = os.path.join(rootfs_license_dir,
88 if [ "${COPY_LIC_DIRS}" = "1" ]; then 88 'license.manifest')
89 for pkg in ${INSTALLED_PKGS}; do 89 os.link(license_manifest, rootfs_license_manifest)
90 mkdir -p ${IMAGE_ROOTFS}/usr/share/common-licenses/${pkg} 90
91 pkged_pn="$(oe-pkgdata-util -p ${PKGDATA_DIR} lookup-recipe ${pkg})" 91 if copy_lic_dirs == "1":
92 for lic in `ls ${LICENSE_DIRECTORY}/${pkged_pn}`; do 92 for pkg in sorted(pkg_dic):
93 # Really don't need to copy the generics as they're 93 pkg_rootfs_license_dir = os.path.join(rootfs_license_dir, pkg)
94 # represented in the manifest and in the actual pkg licenses 94 os.makedirs(pkg_rootfs_license_dir)
95 # Doing so would make your image quite a bit larger 95 pkg_license_dir = os.path.join(d.getVar('LICENSE_DIRECTORY', True),
96 if [ "${lic#generic_}" = "${lic}" ]; then 96 pkg_dic[pkg]["PN"])
97 cp ${LICENSE_DIRECTORY}/${pkged_pn}/${lic} ${IMAGE_ROOTFS}/usr/share/common-licenses/${pkg}/${lic} 97 licenses = os.listdir(pkg_license_dir)
98 else 98 for lic in licenses:
99 if [ ! -f ${IMAGE_ROOTFS}/usr/share/common-licenses/${lic} ]; then 99 rootfs_license = os.path.join(rootfs_license_dir, lic)
100 cp ${LICENSE_DIRECTORY}/${pkged_pn}/${lic} ${IMAGE_ROOTFS}/usr/share/common-licenses/ 100 pkg_license = os.path.join(pkg_license_dir, lic)
101 fi 101 pkg_rootfs_license = os.path.join(pkg_rootfs_license_dir, lic)
102 ln -sf ../${lic} ${IMAGE_ROOTFS}/usr/share/common-licenses/${pkg}/${lic} 102
103 fi 103 if re.match("^generic_.*$", lic):
104 done 104 if not os.path.exists(rootfs_license):
105 done 105 os.link(pkg_license, rootfs_license)
106 fi 106
107 fi 107 os.symlink(os.path.join('..', lic), pkg_rootfs_license)
108 108 else:
109 os.link(pkg_license, pkg_rootfs_license)
109} 110}
110 111
111python do_populate_lic() { 112python do_populate_lic() {