summaryrefslogtreecommitdiff
path: root/yocto-poky/meta/classes/license.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'yocto-poky/meta/classes/license.bbclass')
-rw-r--r--yocto-poky/meta/classes/license.bbclass246
1 files changed, 213 insertions, 33 deletions
diff --git a/yocto-poky/meta/classes/license.bbclass b/yocto-poky/meta/classes/license.bbclass
index 8ad4614d6..43944e6ee 100644
--- a/yocto-poky/meta/classes/license.bbclass
+++ b/yocto-poky/meta/classes/license.bbclass
@@ -21,25 +21,28 @@ python write_package_manifest() {
license_image_dir = d.expand('${LICENSE_DIRECTORY}/${IMAGE_NAME}')
bb.utils.mkdirhier(license_image_dir)
from oe.rootfs import image_list_installed_packages
+ from oe.utils import format_pkg_list
+
+ pkgs = image_list_installed_packages(d)
+ output = format_pkg_list(pkgs)
open(os.path.join(license_image_dir, 'package.manifest'),
- 'w+').write(image_list_installed_packages(d))
+ 'w+').write(output)
+}
+
+python write_deploy_manifest() {
+ license_deployed_manifest(d)
}
python license_create_manifest() {
- import re
import oe.packagedata
from oe.rootfs import image_list_installed_packages
- bad_licenses = (d.getVar("INCOMPATIBLE_LICENSE", True) or "").split()
- bad_licenses = map(lambda l: canonical_license(d, l), bad_licenses)
- bad_licenses = expand_wildcard_licenses(d, bad_licenses)
-
build_images_from_feeds = d.getVar('BUILD_IMAGES_FROM_FEEDS', True)
if build_images_from_feeds == "1":
return 0
pkg_dic = {}
- for pkg in image_list_installed_packages(d).splitlines():
+ for pkg in sorted(image_list_installed_packages(d)):
pkg_info = os.path.join(d.getVar('PKGDATA_DIR', True),
'runtime-reverse', pkg)
pkg_name = os.path.basename(os.readlink(pkg_info))
@@ -49,8 +52,18 @@ python license_create_manifest() {
pkg_lic_name = "LICENSE_" + pkg_name
pkg_dic[pkg_name]["LICENSE"] = pkg_dic[pkg_name][pkg_lic_name]
- license_manifest = os.path.join(d.getVar('LICENSE_DIRECTORY', True),
+ rootfs_license_manifest = os.path.join(d.getVar('LICENSE_DIRECTORY', True),
d.getVar('IMAGE_NAME', True), 'license.manifest')
+ write_license_files(d, rootfs_license_manifest, pkg_dic)
+}
+
+def write_license_files(d, license_manifest, pkg_dic):
+ import re
+
+ bad_licenses = (d.getVar("INCOMPATIBLE_LICENSE", True) or "").split()
+ bad_licenses = map(lambda l: canonical_license(d, l), bad_licenses)
+ bad_licenses = expand_wildcard_licenses(d, bad_licenses)
+
with open(license_manifest, "w") as license_file:
for pkg in sorted(pkg_dic):
if bad_licenses:
@@ -61,20 +74,28 @@ python license_create_manifest() {
except oe.license.LicenseError as exc:
bb.fatal('%s: %s' % (d.getVar('P', True), exc))
else:
- pkg_dic[pkg]["LICENSES"] = re.sub('[|&()*]', '', pkg_dic[pkg]["LICENSE"])
+ pkg_dic[pkg]["LICENSES"] = re.sub('[|&()*]', ' ', pkg_dic[pkg]["LICENSE"])
pkg_dic[pkg]["LICENSES"] = re.sub(' *', ' ', pkg_dic[pkg]["LICENSES"])
pkg_dic[pkg]["LICENSES"] = pkg_dic[pkg]["LICENSES"].split()
- license_file.write("PACKAGE NAME: %s\n" % pkg)
- license_file.write("PACKAGE VERSION: %s\n" % pkg_dic[pkg]["PV"])
- license_file.write("RECIPE NAME: %s\n" % pkg_dic[pkg]["PN"])
- license_file.write("LICENSE: %s\n\n" % pkg_dic[pkg]["LICENSE"])
-
- # If the package doesn't contain any file, that is, its size is 0, the license
- # isn't relevant as far as the final image is concerned. So doing license check
- # doesn't make much sense, skip it.
- if pkg_dic[pkg]["PKGSIZE_%s" % pkg] == "0":
- continue
+ if not "IMAGE_MANIFEST" in pkg_dic[pkg]:
+ # Rootfs manifest
+ license_file.write("PACKAGE NAME: %s\n" % pkg)
+ license_file.write("PACKAGE VERSION: %s\n" % pkg_dic[pkg]["PV"])
+ license_file.write("RECIPE NAME: %s\n" % pkg_dic[pkg]["PN"])
+ license_file.write("LICENSE: %s\n\n" % pkg_dic[pkg]["LICENSE"])
+
+ # If the package doesn't contain any file, that is, its size is 0, the license
+ # isn't relevant as far as the final image is concerned. So doing license check
+ # doesn't make much sense, skip it.
+ if pkg_dic[pkg]["PKGSIZE_%s" % pkg] == "0":
+ continue
+ else:
+ # Image manifest
+ license_file.write("RECIPE NAME: %s\n" % pkg_dic[pkg]["PN"])
+ license_file.write("VERSION: %s\n" % pkg_dic[pkg]["PV"])
+ license_file.write("LICENSE: %s\n" % pkg_dic[pkg]["LICENSE"])
+ license_file.write("FILES: %s\n\n" % pkg_dic[pkg]["FILES"])
for lic in pkg_dic[pkg]["LICENSES"]:
lic_file = os.path.join(d.getVar('LICENSE_DIRECTORY', True),
@@ -98,15 +119,16 @@ python license_create_manifest() {
if copy_lic_manifest == "1":
rootfs_license_dir = os.path.join(d.getVar('IMAGE_ROOTFS', 'True'),
'usr', 'share', 'common-licenses')
- os.makedirs(rootfs_license_dir)
+ bb.utils.mkdirhier(rootfs_license_dir)
rootfs_license_manifest = os.path.join(rootfs_license_dir,
- 'license.manifest')
- os.link(license_manifest, rootfs_license_manifest)
+ os.path.split(license_manifest)[1])
+ if not os.path.exists(rootfs_license_manifest):
+ os.link(license_manifest, rootfs_license_manifest)
if copy_lic_dirs == "1":
for pkg in sorted(pkg_dic):
pkg_rootfs_license_dir = os.path.join(rootfs_license_dir, pkg)
- os.makedirs(pkg_rootfs_license_dir)
+ bb.utils.mkdirhier(pkg_rootfs_license_dir)
pkg_license_dir = os.path.join(d.getVar('LICENSE_DIRECTORY', True),
pkg_dic[pkg]["PN"])
licenses = os.listdir(pkg_license_dir)
@@ -124,14 +146,145 @@ python license_create_manifest() {
if not os.path.exists(rootfs_license):
os.link(pkg_license, rootfs_license)
- os.symlink(os.path.join('..', lic), pkg_rootfs_license)
+ if not os.path.exists(pkg_rootfs_license):
+ os.symlink(os.path.join('..', lic), pkg_rootfs_license)
else:
- if oe.license.license_ok(canonical_license(d,
- lic), bad_licenses) == False:
+ if (oe.license.license_ok(canonical_license(d,
+ lic), bad_licenses) == False or
+ os.path.exists(pkg_rootfs_license)):
continue
os.link(pkg_license, pkg_rootfs_license)
-}
+
+
+def license_deployed_manifest(d):
+ """
+ Write the license manifest for the deployed recipes.
+ The deployed recipes usually includes the bootloader
+ and extra files to boot the target.
+ """
+
+ dep_dic = {}
+ man_dic = {}
+ lic_dir = d.getVar("LICENSE_DIRECTORY", True)
+
+ dep_dic = get_deployed_dependencies(d)
+ for dep in dep_dic.keys():
+ man_dic[dep] = {}
+ # It is necessary to mark this will be used for image manifest
+ man_dic[dep]["IMAGE_MANIFEST"] = True
+ man_dic[dep]["PN"] = dep
+ man_dic[dep]["FILES"] = \
+ " ".join(get_deployed_files(dep_dic[dep]))
+ with open(os.path.join(lic_dir, dep, "recipeinfo"), "r") as f:
+ for line in f.readlines():
+ 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')
+ write_license_files(d, image_license_manifest, man_dic)
+
+def get_deployed_dependencies(d):
+ """
+ Get all the deployed dependencies of an image
+ """
+
+ deploy = {}
+ # Get all the dependencies for the current task (rootfs).
+ # Also get EXTRA_IMAGEDEPENDS because the bootloader is
+ # usually in this var and not listed in rootfs.
+ # At last, get the dependencies from boot classes because
+ # it might contain the bootloader.
+ taskdata = d.getVar("BB_TASKDEPDATA", False)
+ depends = list(set([dep[0] for dep
+ in taskdata.itervalues()
+ if not dep[0].endswith("-native")]))
+ extra_depends = d.getVar("EXTRA_IMAGEDEPENDS", True)
+ boot_depends = get_boot_dependencies(d)
+ depends.extend(extra_depends.split())
+ depends.extend(boot_depends)
+ depends = list(set(depends))
+
+ # To verify what was deployed it checks the rootfs dependencies against
+ # the SSTATE_MANIFESTS for "deploy" task.
+ # The manifest file name contains the arch. Because we are not running
+ # in the recipe context it is necessary to check every arch used.
+ sstate_manifest_dir = d.getVar("SSTATE_MANIFESTS", True)
+ sstate_archs = d.getVar("SSTATE_ARCHS", True)
+ extra_archs = d.getVar("PACKAGE_EXTRA_ARCHS", True)
+ archs = list(set(("%s %s" % (sstate_archs, extra_archs)).split()))
+ for dep in depends:
+ # Some recipes have an arch on their own, so we try that first.
+ special_arch = d.getVar("PACKAGE_ARCH_pn-%s" % dep, True)
+ if special_arch:
+ sstate_manifest_file = os.path.join(sstate_manifest_dir,
+ "manifest-%s-%s.deploy" % (special_arch, dep))
+ if os.path.exists(sstate_manifest_file):
+ deploy[dep] = sstate_manifest_file
+ continue
+
+ for arch in archs:
+ sstate_manifest_file = os.path.join(sstate_manifest_dir,
+ "manifest-%s-%s.deploy" % (arch, dep))
+ if os.path.exists(sstate_manifest_file):
+ deploy[dep] = sstate_manifest_file
+ break
+
+ return deploy
+get_deployed_dependencies[vardepsexclude] = "BB_TASKDEPDATA"
+
+def get_boot_dependencies(d):
+ """
+ Return the dependencies from boot tasks
+ """
+
+ depends = []
+ boot_depends_string = ""
+ taskdepdata = d.getVar("BB_TASKDEPDATA", False)
+ # Only bootimg and bootdirectdisk include the depends flag
+ boot_tasks = ["do_bootimg", "do_bootdirectdisk",]
+
+ for task in boot_tasks:
+ boot_depends_string = "%s %s" % (boot_depends_string,
+ d.getVarFlag(task, "depends", True) or "")
+ boot_depends = [dep.split(":")[0] for dep
+ in boot_depends_string.split()
+ if not dep.split(":")[0].endswith("-native")]
+ for dep in boot_depends:
+ info_file = os.path.join(d.getVar("LICENSE_DIRECTORY", True),
+ dep, "recipeinfo")
+ # If the recipe and dependency name is the same
+ if os.path.exists(info_file):
+ depends.append(dep)
+ # We need to search for the provider of the dependency
+ else:
+ for taskdep in taskdepdata.itervalues():
+ # The fifth field contains what the task provides
+ if dep in taskdep[4]:
+ info_file = os.path.join(
+ d.getVar("LICENSE_DIRECTORY", True),
+ taskdep[0], "recipeinfo")
+ if os.path.exists(info_file):
+ depends.append(taskdep[0])
+ break
+ return depends
+get_boot_dependencies[vardepsexclude] = "BB_TASKDEPDATA"
+
+def get_deployed_files(man_file):
+ """
+ Get the files deployed from the sstate manifest
+ """
+
+ dep_files = []
+ excluded_files = ["README_-_DO_NOT_DELETE_FILES_IN_THIS_DIRECTORY.txt"]
+ with open(man_file, "r") as manifest:
+ all_files = manifest.read()
+ for f in all_files.splitlines():
+ if ((not (os.path.islink(f) or os.path.isdir(f))) and
+ not os.path.basename(f) in excluded_files):
+ dep_files.append(os.path.basename(f))
+ return dep_files
python do_populate_lic() {
"""
@@ -142,6 +295,10 @@ python do_populate_lic() {
# The base directory we wrangle licenses to
destdir = os.path.join(d.getVar('LICSSTATEDIR', True), d.getVar('PN', True))
copy_license_files(lic_files_paths, destdir)
+ info = get_recipe_info(d)
+ with open(os.path.join(destdir, "recipeinfo"), "w") as f:
+ for key in sorted(info.keys()):
+ f.write("%s: %s\n" % (key, info[key]))
}
# it would be better to copy them in do_install_append, but find_license_filesa is python
@@ -155,6 +312,14 @@ python perform_packagecopy_prepend () {
copy_license_files(lic_files_paths, destdir)
add_package_and_files(d)
}
+perform_packagecopy[vardeps] += "LICENSE_CREATE_PACKAGE"
+
+def get_recipe_info(d):
+ info = {}
+ info["PV"] = d.getVar("PV", True)
+ info["PR"] = d.getVar("PR", True)
+ info["LICENSE"] = d.getVar("LICENSE", True)
+ return info
def add_package_and_files(d):
packages = d.getVar('PACKAGES', True)
@@ -185,6 +350,18 @@ def copy_license_files(lic_files_paths, destdir):
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)
+ try:
+ 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.
+ # Also ignore "Invalid argument" errors that happen in
+ # some (unprivileged) container environments (no root).
+ pass
+ else:
+ raise
else:
shutil.copyfile(src, dst)
except Exception as e:
@@ -252,10 +429,10 @@ def find_license_files(d):
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:
+ if d.getVarFlag('SPDXLICENSEMAP', license_type, True) != 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)
+ spdx_generic = d.getVarFlag('SPDXLICENSEMAP', license_type, True)
license_source = lic_dir
break
elif os.path.isfile(os.path.join(lic_dir, license_type)):
@@ -271,14 +448,14 @@ def find_license_files(d):
# 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):
+ 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):
+ elif d.getVarFlag('NO_GENERIC_LICENSE', license_type, True):
# 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) == basename:
+ if d.getVarFlag('NO_GENERIC_LICENSE', license_type, True) == basename:
lic_files_paths.append(("generic_" + license_type, path))
break
else:
@@ -346,7 +523,7 @@ def expand_wildcard_licenses(d, wildcard_licenses):
spdxmapkeys = d.getVarFlags('SPDXLICENSEMAP').keys()
for wld_lic in wildcard_licenses:
spdxflags = fnmatch.filter(spdxmapkeys, wld_lic)
- licenses += [d.getVarFlag('SPDXLICENSEMAP', flag) for flag in spdxflags]
+ licenses += [d.getVarFlag('SPDXLICENSEMAP', flag, True) for flag in spdxflags]
spdx_lics = (d.getVar('SRC_DISTRIBUTE_LICENSES', False) or '').split()
for wld_lic in wildcard_licenses:
@@ -476,6 +653,9 @@ do_populate_lic[sstate-outputdirs] = "${LICENSE_DIRECTORY}/"
ROOTFS_POSTPROCESS_COMMAND_prepend = "write_package_manifest; license_create_manifest; "
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 () {