2011-04-21 11:26:25 +00:00
|
|
|
# Populates LICENSE_DIRECTORY as set in distro config with the license files as set by
|
2011-12-05 01:03:37 +00:00
|
|
|
# LIC_FILES_CHKSUM.
|
2011-01-27 19:25:12 +00:00
|
|
|
# TODO:
|
2011-12-03 23:16:15 +00:00
|
|
|
# - There is a real issue revolving around license naming standards.
|
2011-01-27 19:25:12 +00:00
|
|
|
|
2011-05-17 09:47:53 +00:00
|
|
|
LICENSE_DIRECTORY ??= "${DEPLOY_DIR}/licenses"
|
2011-02-03 12:33:18 +00:00
|
|
|
LICSSTATEDIR = "${WORKDIR}/license-destdir/"
|
2011-01-27 19:25:12 +00:00
|
|
|
|
2013-01-17 11:49:44 +00:00
|
|
|
# Create extra package with license texts and add it to RRECOMMENDS_${PN}
|
2013-01-29 21:17:20 +00:00
|
|
|
LICENSE_CREATE_PACKAGE[type] = "boolean"
|
2013-01-17 11:49:44 +00:00
|
|
|
LICENSE_CREATE_PACKAGE ??= "0"
|
|
|
|
LICENSE_PACKAGE_SUFFIX ??= "-lic"
|
|
|
|
LICENSE_FILES_DIRECTORY ??= "${datadir}/licenses/"
|
|
|
|
|
2012-11-16 18:26:44 +00:00
|
|
|
addtask populate_lic after do_patch before do_build
|
2011-02-03 12:33:18 +00:00
|
|
|
do_populate_lic[dirs] = "${LICSSTATEDIR}/${PN}"
|
|
|
|
do_populate_lic[cleandirs] = "${LICSSTATEDIR}"
|
2011-05-25 20:58:35 +00:00
|
|
|
|
2014-01-27 01:41:31 +00:00
|
|
|
python write_package_manifest() {
|
2014-07-18 12:41:34 +00:00
|
|
|
# Get list of installed packages
|
|
|
|
license_image_dir = d.expand('${LICENSE_DIRECTORY}/${IMAGE_NAME}')
|
|
|
|
bb.utils.mkdirhier(license_image_dir)
|
|
|
|
from oe.rootfs import image_list_installed_packages
|
|
|
|
open(os.path.join(license_image_dir, 'package.manifest'),
|
|
|
|
'w+').write(image_list_installed_packages(d))
|
2014-01-27 01:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
license_create_manifest() {
|
2014-02-11 15:00:05 +00:00
|
|
|
# Test if BUILD_IMAGES_FROM_FEEDS is defined in env
|
|
|
|
if [ -n "${BUILD_IMAGES_FROM_FEEDS}" ]; then
|
|
|
|
exit 0
|
|
|
|
fi
|
|
|
|
|
2012-03-23 23:51:44 +00:00
|
|
|
INSTALLED_PKGS=`cat ${LICENSE_DIRECTORY}/${IMAGE_NAME}/package.manifest`
|
2012-09-11 01:13:43 +00:00
|
|
|
LICENSE_MANIFEST="${LICENSE_DIRECTORY}/${IMAGE_NAME}/license.manifest"
|
2012-03-29 12:22:29 +00:00
|
|
|
# remove existing license.manifest file
|
2012-09-11 01:13:43 +00:00
|
|
|
if [ -f ${LICENSE_MANIFEST} ]; then
|
|
|
|
rm ${LICENSE_MANIFEST}
|
2012-03-29 12:22:29 +00:00
|
|
|
fi
|
2012-12-01 18:26:00 +00:00
|
|
|
touch ${LICENSE_MANIFEST}
|
2012-03-23 23:51:44 +00:00
|
|
|
for pkg in ${INSTALLED_PKGS}; do
|
2013-09-13 12:35:31 +00:00
|
|
|
filename=`ls ${PKGDATA_DIR}/runtime-reverse/${pkg}| head -1`
|
2012-05-30 19:01:15 +00:00
|
|
|
pkged_pn="$(sed -n 's/^PN: //p' ${filename})"
|
2012-09-11 01:13:45 +00:00
|
|
|
|
|
|
|
# check to see if the package name exists in the manifest. if so, bail.
|
|
|
|
if grep -q "^PACKAGE NAME: ${pkg}" ${LICENSE_MANIFEST}; then
|
|
|
|
continue
|
|
|
|
fi
|
|
|
|
|
2012-05-30 19:01:15 +00:00
|
|
|
pkged_pv="$(sed -n 's/^PV: //p' ${filename})"
|
2012-09-11 01:18:14 +00:00
|
|
|
pkged_name="$(basename $(readlink ${filename}))"
|
2012-09-11 01:18:15 +00:00
|
|
|
pkged_lic="$(sed -n "/^LICENSE_${pkged_name}: /{ s/^LICENSE_${pkged_name}: //; s/[|&()*]/ /g; s/ */ /g; p }" ${filename})"
|
2012-09-11 01:18:14 +00:00
|
|
|
if [ -z ${pkged_lic} ]; then
|
|
|
|
# fallback checking value of LICENSE
|
2012-09-11 01:18:15 +00:00
|
|
|
pkged_lic="$(sed -n "/^LICENSE: /{ s/^LICENSE: //; s/[|&()*]/ /g; s/ */ /g; p }" ${filename})"
|
2012-09-11 01:18:14 +00:00
|
|
|
fi
|
2012-09-11 01:13:45 +00:00
|
|
|
|
|
|
|
echo "PACKAGE NAME:" ${pkg} >> ${LICENSE_MANIFEST}
|
|
|
|
echo "PACKAGE VERSION:" ${pkged_pv} >> ${LICENSE_MANIFEST}
|
|
|
|
echo "RECIPE NAME:" ${pkged_pn} >> ${LICENSE_MANIFEST}
|
2012-09-20 09:56:59 +00:00
|
|
|
printf "LICENSE:" >> ${LICENSE_MANIFEST}
|
2012-09-11 01:13:45 +00:00
|
|
|
for lic in ${pkged_lic}; do
|
2012-09-11 01:18:15 +00:00
|
|
|
# to reference a license file trim trailing + symbol
|
2013-06-10 23:15:50 +00:00
|
|
|
if ! [ -e "${LICENSE_DIRECTORY}/${pkged_pn}/generic_${lic%+}" ]; then
|
|
|
|
bbwarn "The license listed ${lic} was not in the licenses collected for ${pkged_pn}"
|
2012-03-23 23:51:44 +00:00
|
|
|
fi
|
2013-06-10 23:15:50 +00:00
|
|
|
printf " ${lic}" >> ${LICENSE_MANIFEST}
|
2012-09-11 01:13:45 +00:00
|
|
|
done
|
2012-09-20 09:56:59 +00:00
|
|
|
printf "\n\n" >> ${LICENSE_MANIFEST}
|
2012-03-23 23:51:44 +00:00
|
|
|
done
|
|
|
|
|
|
|
|
# Two options here:
|
|
|
|
# - Just copy the manifest
|
|
|
|
# - Copy the manifest and the license directories
|
|
|
|
# With both options set we see a .5 M increase in core-image-minimal
|
2013-11-13 14:32:44 +00:00
|
|
|
if [ "${COPY_LIC_MANIFEST}" = "1" ]; then
|
2012-03-23 23:51:44 +00:00
|
|
|
mkdir -p ${IMAGE_ROOTFS}/usr/share/common-licenses/
|
2012-09-11 01:13:43 +00:00
|
|
|
cp ${LICENSE_MANIFEST} ${IMAGE_ROOTFS}/usr/share/common-licenses/license.manifest
|
2013-11-13 14:32:44 +00:00
|
|
|
if [ "${COPY_LIC_DIRS}" = "1" ]; then
|
2012-03-23 23:51:44 +00:00
|
|
|
for pkg in ${INSTALLED_PKGS}; do
|
|
|
|
mkdir -p ${IMAGE_ROOTFS}/usr/share/common-licenses/${pkg}
|
2013-11-20 10:35:39 +00:00
|
|
|
pkged_pn="$(oe-pkgdata-util lookup-recipe ${PKGDATA_DIR} ${pkg})"
|
|
|
|
for lic in `ls ${LICENSE_DIRECTORY}/${pkged_pn}`; do
|
2012-03-23 23:51:44 +00:00
|
|
|
# Really don't need to copy the generics as they're
|
|
|
|
# represented in the manifest and in the actual pkg licenses
|
|
|
|
# Doing so would make your image quite a bit larger
|
2013-11-18 07:20:44 +00:00
|
|
|
if [ "${lic#generic_}" = "${lic}" ]; then
|
2013-11-20 10:35:39 +00:00
|
|
|
cp ${LICENSE_DIRECTORY}/${pkged_pn}/${lic} ${IMAGE_ROOTFS}/usr/share/common-licenses/${pkg}/${lic}
|
2013-11-18 07:20:44 +00:00
|
|
|
else
|
2012-03-23 23:51:44 +00:00
|
|
|
if [ ! -f ${IMAGE_ROOTFS}/usr/share/common-licenses/${lic} ]; then
|
2013-11-20 10:35:39 +00:00
|
|
|
cp ${LICENSE_DIRECTORY}/${pkged_pn}/${lic} ${IMAGE_ROOTFS}/usr/share/common-licenses/
|
2012-03-23 23:51:44 +00:00
|
|
|
fi
|
2014-01-27 01:49:08 +00:00
|
|
|
ln -sf ../${lic} ${IMAGE_ROOTFS}/usr/share/common-licenses/${pkg}/${lic}
|
2012-03-23 23:51:44 +00:00
|
|
|
fi
|
|
|
|
done
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
2011-12-03 23:16:15 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2011-01-27 19:25:12 +00:00
|
|
|
python do_populate_lic() {
|
|
|
|
"""
|
|
|
|
Populate LICENSE_DIRECTORY with licenses.
|
|
|
|
"""
|
2013-01-17 11:49:43 +00:00
|
|
|
lic_files_paths = find_license_files(d)
|
|
|
|
|
|
|
|
# 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)
|
|
|
|
}
|
|
|
|
|
2013-01-17 11:49:44 +00:00
|
|
|
# it would be better to copy them in do_install_append, but find_license_filesa is python
|
|
|
|
python perform_packagecopy_prepend () {
|
2013-01-29 21:17:20 +00:00
|
|
|
enabled = oe.data.typed_value('LICENSE_CREATE_PACKAGE', d)
|
2013-01-17 11:49:44 +00:00
|
|
|
if d.getVar('CLASSOVERRIDE', True) == 'class-target' and enabled:
|
|
|
|
lic_files_paths = find_license_files(d)
|
|
|
|
|
|
|
|
# LICENSE_FILES_DIRECTORY starts with '/' so os.path.join cannot be used to join D and LICENSE_FILES_DIRECTORY
|
|
|
|
destdir = d.getVar('D', True) + os.path.join(d.getVar('LICENSE_FILES_DIRECTORY', True), d.getVar('PN', True))
|
|
|
|
copy_license_files(lic_files_paths, destdir)
|
|
|
|
add_package_and_files(d)
|
|
|
|
}
|
|
|
|
|
|
|
|
def add_package_and_files(d):
|
|
|
|
packages = d.getVar('PACKAGES', True)
|
|
|
|
files = d.getVar('LICENSE_FILES_DIRECTORY', True)
|
|
|
|
pn = d.getVar('PN', True)
|
|
|
|
pn_lic = "%s%s" % (pn, d.getVar('LICENSE_PACKAGE_SUFFIX'))
|
|
|
|
if pn_lic in packages:
|
|
|
|
bb.warn("%s package already existed in %s." % (pn_lic, pn))
|
|
|
|
else:
|
|
|
|
# first in PACKAGES to be sure that nothing else gets LICENSE_FILES_DIRECTORY
|
|
|
|
d.setVar('PACKAGES', "%s %s" % (pn_lic, packages))
|
|
|
|
d.setVar('FILES_' + pn_lic, files)
|
|
|
|
rrecommends_pn = d.getVar('RRECOMMENDS_' + pn, True)
|
|
|
|
if rrecommends_pn:
|
|
|
|
d.setVar('RRECOMMENDS_' + pn, "%s %s" % (pn_lic, rrecommends_pn))
|
|
|
|
else:
|
|
|
|
d.setVar('RRECOMMENDS_' + pn, "%s" % (pn_lic))
|
|
|
|
|
2013-01-17 11:49:43 +00:00
|
|
|
def copy_license_files(lic_files_paths, destdir):
|
2013-10-02 16:30:21 +00:00
|
|
|
import shutil
|
|
|
|
|
2013-09-01 07:52:40 +00:00
|
|
|
bb.utils.mkdirhier(destdir)
|
2013-01-17 11:49:43 +00:00
|
|
|
for (basename, path) in lic_files_paths:
|
2013-10-02 16:30:21 +00:00
|
|
|
try:
|
2014-09-12 15:39:49 +00:00
|
|
|
src = path
|
|
|
|
dst = os.path.join(destdir, basename)
|
|
|
|
if os.path.exists(dst):
|
|
|
|
os.remove(dst)
|
|
|
|
if (os.stat(src).st_dev == os.stat(destdir).st_dev):
|
|
|
|
os.link(src, dst)
|
|
|
|
else:
|
|
|
|
shutil.copyfile(src, dst)
|
2013-10-02 16:30:21 +00:00
|
|
|
except Exception as e:
|
|
|
|
bb.warn("Could not copy license file %s: %s" % (basename, e))
|
2013-01-17 11:49:43 +00:00
|
|
|
|
|
|
|
def find_license_files(d):
|
|
|
|
"""
|
|
|
|
Creates list of files used in LIC_FILES_CHKSUM and generic LICENSE files.
|
|
|
|
"""
|
2011-01-27 19:25:12 +00:00
|
|
|
import shutil
|
2011-12-05 01:03:37 +00:00
|
|
|
import oe.license
|
2011-05-25 20:58:35 +00:00
|
|
|
|
2012-02-24 22:17:38 +00:00
|
|
|
pn = d.getVar('PN', True)
|
|
|
|
for package in d.getVar('PACKAGES', True):
|
2012-11-20 21:49:56 +00:00
|
|
|
if d.getVar('LICENSE_' + package, True):
|
2012-02-24 22:17:38 +00:00
|
|
|
license_types = license_types + ' & ' + \
|
2012-11-20 21:49:56 +00:00
|
|
|
d.getVar('LICENSE_' + package, True)
|
2012-02-24 22:17:38 +00:00
|
|
|
|
|
|
|
#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)
|
|
|
|
|
2011-12-03 23:16:15 +00:00
|
|
|
# All the license files for the package
|
|
|
|
lic_files = d.getVar('LIC_FILES_CHKSUM', True)
|
|
|
|
pn = d.getVar('PN', True)
|
|
|
|
# The license files are located in S/LIC_FILE_CHECKSUM.
|
|
|
|
srcdir = d.getVar('S', True)
|
|
|
|
# Directory we store the generic licenses as set in the distro configuration
|
|
|
|
generic_directory = d.getVar('COMMON_LICENSE_DIR', True)
|
2013-01-17 11:49:43 +00:00
|
|
|
# List of basename, path tuples
|
|
|
|
lic_files_paths = []
|
2011-12-03 23:16:15 +00:00
|
|
|
license_source_dirs = []
|
|
|
|
license_source_dirs.append(generic_directory)
|
|
|
|
try:
|
2012-09-26 21:50:07 +00:00
|
|
|
additional_lic_dirs = d.getVar('LICENSE_PATH', True).split()
|
2011-12-03 23:16:15 +00:00
|
|
|
for lic_dir in additional_lic_dirs:
|
|
|
|
license_source_dirs.append(lic_dir)
|
|
|
|
except:
|
|
|
|
pass
|
|
|
|
|
2011-12-05 01:03:37 +00:00
|
|
|
class FindVisitor(oe.license.LicenseVisitor):
|
2011-05-25 20:58:35 +00:00
|
|
|
def visit_Str(self, node):
|
|
|
|
#
|
|
|
|
# Until I figure out what to do with
|
|
|
|
# the two modifiers I support (or greater = +
|
|
|
|
# and "with exceptions" being *
|
2011-12-05 01:03:37 +00:00
|
|
|
# we'll just strip out the modifier and put
|
2011-05-25 20:58:35 +00:00
|
|
|
# the base license.
|
|
|
|
find_license(node.s.replace("+", "").replace("*", ""))
|
2011-12-05 01:03:37 +00:00
|
|
|
self.generic_visit(node)
|
2011-05-25 20:58:35 +00:00
|
|
|
|
|
|
|
def find_license(license_type):
|
|
|
|
try:
|
2013-09-01 07:52:40 +00:00
|
|
|
bb.utils.mkdirhier(gen_lic_dest)
|
2011-05-25 20:58:35 +00:00
|
|
|
except:
|
|
|
|
pass
|
2011-12-03 23:16:15 +00:00
|
|
|
spdx_generic = None
|
|
|
|
license_source = None
|
2011-05-25 20:58:35 +00:00
|
|
|
# If the generic does not exist we need to check to see if there is an SPDX mapping to it
|
2011-12-03 23:16:15 +00:00
|
|
|
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
|
|
|
|
|
|
|
|
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)
|
2012-04-03 11:05:48 +00:00
|
|
|
|
2013-01-17 11:49:43 +00:00
|
|
|
lic_files_paths.append(("generic_" + license_type, os.path.join(license_source, spdx_generic)))
|
2011-12-03 23:16:15 +00:00
|
|
|
else:
|
|
|
|
# And here is where we warn people that their licenses are lousy
|
|
|
|
bb.warn("%s: No generic license file exists for: %s in any provider" % (pn, license_type))
|
|
|
|
pass
|
2011-12-05 01:03:37 +00:00
|
|
|
|
2011-01-27 19:25:12 +00:00
|
|
|
if not generic_directory:
|
|
|
|
raise bb.build.FuncFailed("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
|
|
|
|
# where, but let's be pedantic
|
|
|
|
bb.note(pn + ": Recipe file does not have license file information.")
|
2013-01-17 11:49:43 +00:00
|
|
|
return lic_files_paths
|
2011-01-27 19:25:12 +00:00
|
|
|
|
|
|
|
for url in lic_files.split():
|
2013-11-12 13:29:24 +00:00
|
|
|
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))
|
2013-01-17 11:49:43 +00:00
|
|
|
# We want the license filename and path
|
2011-01-27 19:25:12 +00:00
|
|
|
srclicfile = os.path.join(srcdir, path)
|
2013-01-17 11:49:43 +00:00
|
|
|
lic_files_paths.append((os.path.basename(path), srclicfile))
|
2011-12-05 01:03:37 +00:00
|
|
|
|
|
|
|
v = FindVisitor()
|
|
|
|
try:
|
|
|
|
v.visit_string(license_types)
|
|
|
|
except oe.license.InvalidLicense as exc:
|
2011-12-10 00:05:24 +00:00
|
|
|
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)))
|
|
|
|
|
2013-01-17 11:49:43 +00:00
|
|
|
return lic_files_paths
|
2011-02-03 12:33:18 +00:00
|
|
|
|
2012-03-23 23:51:42 +00:00
|
|
|
def return_spdx(d, license):
|
|
|
|
"""
|
2012-11-29 19:08:47 +00:00
|
|
|
This function returns the spdx mapping of a license if it exists.
|
|
|
|
"""
|
|
|
|
return d.getVarFlag('SPDXLICENSEMAP', license, True)
|
2012-03-23 23:51:42 +00:00
|
|
|
|
2014-07-17 14:41:05 +00:00
|
|
|
def canonical_license(d, license):
|
|
|
|
"""
|
|
|
|
Return the canonical (SPDX) form of the license if available (so GPLv3
|
2014-10-27 07:37:41 +00:00
|
|
|
becomes GPL-3.0), for the license named 'X+', return canonical form of
|
|
|
|
'X' if availabel and the tailing '+' (so GPLv3+ becomes GPL-3.0+),
|
|
|
|
or the passed license if there is no canonical form.
|
2014-07-17 14:41:05 +00:00
|
|
|
"""
|
2014-10-27 07:37:41 +00:00
|
|
|
lic = d.getVarFlag('SPDXLICENSEMAP', license, True) or ""
|
|
|
|
if not lic and license.endswith('+'):
|
|
|
|
lic = d.getVarFlag('SPDXLICENSEMAP', license.rstrip('+'), True)
|
|
|
|
if lic:
|
|
|
|
lic += '+'
|
|
|
|
return lic or license
|
2014-07-17 14:41:05 +00:00
|
|
|
|
2012-11-29 19:08:47 +00:00
|
|
|
def incompatible_license(d, dont_want_licenses, package=None):
|
2012-03-23 23:51:42 +00:00
|
|
|
"""
|
2014-07-17 14:41:05 +00:00
|
|
|
This function checks if a recipe has only incompatible licenses. It also
|
|
|
|
take into consideration 'or' operand. dont_want_licenses should be passed
|
|
|
|
as canonical (SPDX) names.
|
2012-01-10 15:17:58 +00:00
|
|
|
"""
|
|
|
|
import re
|
|
|
|
import oe.license
|
|
|
|
from fnmatch import fnmatchcase as fnmatch
|
2013-01-15 20:22:46 +00:00
|
|
|
license = d.getVar("LICENSE_%s" % package, True) if package else None
|
2012-11-29 19:08:47 +00:00
|
|
|
if not license:
|
|
|
|
license = d.getVar('LICENSE', True)
|
|
|
|
|
|
|
|
def license_ok(license):
|
|
|
|
for dwl in dont_want_licenses:
|
|
|
|
# If you want to exclude license named generically 'X', we
|
|
|
|
# surely want to exclude 'X+' as well. In consequence, we
|
|
|
|
# will exclude a trailing '+' character from LICENSE in
|
|
|
|
# case INCOMPATIBLE_LICENSE is not a 'X+' license.
|
|
|
|
lic = license
|
2013-01-15 20:22:47 +00:00
|
|
|
if not re.search('\+$', dwl):
|
|
|
|
lic = re.sub('\+', '', license)
|
|
|
|
if fnmatch(lic, dwl):
|
|
|
|
return False
|
2012-11-29 19:08:47 +00:00
|
|
|
return True
|
2012-01-10 15:17:58 +00:00
|
|
|
|
2012-11-29 19:08:47 +00:00
|
|
|
# Handles an "or" or two license sets provided by
|
|
|
|
# flattened_licenses(), pick one that works if possible.
|
|
|
|
def choose_lic_set(a, b):
|
|
|
|
return a if all(license_ok(lic) for lic in a) else b
|
2012-01-10 15:17:58 +00:00
|
|
|
|
2013-01-15 20:22:48 +00:00
|
|
|
try:
|
|
|
|
licenses = oe.license.flattened_licenses(license, choose_lic_set)
|
|
|
|
except oe.license.LicenseError as exc:
|
|
|
|
bb.fatal('%s: %s' % (d.getVar('P', True), exc))
|
2014-07-17 14:41:05 +00:00
|
|
|
return any(not license_ok(canonical_license(d, l)) for l in licenses)
|
2012-01-10 15:17:58 +00:00
|
|
|
|
license.bbclass: add support for LICENSE_FLAGS
LICENSE_FLAGS are a per-recipe replacement for the COMMERCIAL_LICENSE
mechanism.
In the COMMERCIAL_LICENSE mechanism, any package name mentioned in the
global COMMERCIAL_LICENSE list is 'blacklisted' from being included in
an image. To allow the blacklisted package into the image, the
corresponding packages need to be removed from the COMMERCIAL_LICENSE
list. This mechanism relies on a global list defined in
default-distrovars.inc.
The LICENSE_FLAGS mechanism essentially implements the same thing but
turns the global blacklist into a per-recipe whitelist. Any recipe
can optionally define one or more 'license flags'; if defined, each of
the license flags defined for a recipe must have matching entries in a
global LICENSE_FLAGS_WHITELIST variable.
The definition of 'matching' is simple, but there are a couple things
users need to know in order to correctly and effectively use it.
Before we test a flag against the whitelist, we append _${PN} to it,
thus automatically making each LICENSE_FLAG recipe-specific. We then
try to match that string against the whitelist. So if the user
specifies LICENSE_FLAGS = 'commercial' for recipe 'foo', the string
'commercial_foo' should be specified in the whitelist in order for it
to match.
However, the user can also broaden the match by putting any
'_'-separated beginning subset of a LICENSE_FLAG in the whitelist,
which will also match e.g. simply specifying 'commercial' in the
whitelist would match any expanded LICENSE_FLAG starting with
'commercial' such as 'commercial_foo' and 'commercial_bar' which are
the strings that would have been automatically generated if those
recipes had simply specified LICENSE_FLAGS = 'commercial'
This allows for a range of specificity for the items in the whitelist,
from more general to perfectly specific. So users have the choice of
exhaustively enumerating each license flag in the whitelist to allow
only those specific recipes into the image, or of using a more general
string to pick up anything matching just the first component(s).
Note that this scheme works even if the flag already has _pn appended
- the extra _pn is redundant, but doesn't affect the outcome e.g. a
license flag of 'commercial_1.2_foo' would turn into
'commercial_1.2_foo_foo' and would match both the general 'commercial'
and the specific 'commercial_1.2_foo' as expected (it would also match
commercial_1.2_foo_foo' and 'commercial_1.2', which don't make much
sense as far as something a user would think of specifying in the
whitelist). For a versioned string, the user could instead specify
'commercial_foo_1.2', which would turn into 'commercial_foo_1.2_foo',
but which would as expected allow the user to pick up this package
along with anything else 'commercial' by specifying 'commercial' in
the whitelist, or anything with a 'commercial_foo' license regardless
of version by using 'commercial_foo' in the whitelist, or
'commercial_foo_1.1' to be completely specific about package and
version.
The current behavior of COMMERCIAL_LICENSE is replicated as mentioned
above by having the current set of COMMERCIAL_LICENSE flags
implemented using LICENSE_FLAGS = "commercial".
That being the case, the current COMMERCIAL_LICENSE can equivalently
be specified in the new scheme by putting the below in local.conf:
# This is a list of packages that require a commercial license to ship
# product. If shipped as part of an image these packages may have
# implications so they are disabled by default. To enable them,
# un-comment the below as appropriate.
#LICENSE_FLAGS_WHITELIST = "commercial_gst-fluendo-mp3 \
# commercial_gst-openmax \
# commercial_gst-plugins-ugly \
# commercial_lame \
# commercial_libmad \
# commercial_libomxil \
# commercial_mpeg2dec \
# commercial_qmmp"
The above allows all of the current COMMERCIAL_LICENSE packages in -
to disallow a particular package from appearing in the image, simply
remove it from the whitelist. To allow them all in, you could also
specify LICENSE_FLAGS_WHITELIST = "commercial".
(From OE-Core rev: a2760661b8c7a4a1b6f2e556853b3a9ae38cbcb5)
Signed-off-by: Tom Zanussi <tom.zanussi@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2011-12-31 19:06:39 +00:00
|
|
|
def check_license_flags(d):
|
|
|
|
"""
|
2013-11-13 14:32:45 +00:00
|
|
|
This function checks if a recipe has any LICENSE_FLAGS that
|
license.bbclass: add support for LICENSE_FLAGS
LICENSE_FLAGS are a per-recipe replacement for the COMMERCIAL_LICENSE
mechanism.
In the COMMERCIAL_LICENSE mechanism, any package name mentioned in the
global COMMERCIAL_LICENSE list is 'blacklisted' from being included in
an image. To allow the blacklisted package into the image, the
corresponding packages need to be removed from the COMMERCIAL_LICENSE
list. This mechanism relies on a global list defined in
default-distrovars.inc.
The LICENSE_FLAGS mechanism essentially implements the same thing but
turns the global blacklist into a per-recipe whitelist. Any recipe
can optionally define one or more 'license flags'; if defined, each of
the license flags defined for a recipe must have matching entries in a
global LICENSE_FLAGS_WHITELIST variable.
The definition of 'matching' is simple, but there are a couple things
users need to know in order to correctly and effectively use it.
Before we test a flag against the whitelist, we append _${PN} to it,
thus automatically making each LICENSE_FLAG recipe-specific. We then
try to match that string against the whitelist. So if the user
specifies LICENSE_FLAGS = 'commercial' for recipe 'foo', the string
'commercial_foo' should be specified in the whitelist in order for it
to match.
However, the user can also broaden the match by putting any
'_'-separated beginning subset of a LICENSE_FLAG in the whitelist,
which will also match e.g. simply specifying 'commercial' in the
whitelist would match any expanded LICENSE_FLAG starting with
'commercial' such as 'commercial_foo' and 'commercial_bar' which are
the strings that would have been automatically generated if those
recipes had simply specified LICENSE_FLAGS = 'commercial'
This allows for a range of specificity for the items in the whitelist,
from more general to perfectly specific. So users have the choice of
exhaustively enumerating each license flag in the whitelist to allow
only those specific recipes into the image, or of using a more general
string to pick up anything matching just the first component(s).
Note that this scheme works even if the flag already has _pn appended
- the extra _pn is redundant, but doesn't affect the outcome e.g. a
license flag of 'commercial_1.2_foo' would turn into
'commercial_1.2_foo_foo' and would match both the general 'commercial'
and the specific 'commercial_1.2_foo' as expected (it would also match
commercial_1.2_foo_foo' and 'commercial_1.2', which don't make much
sense as far as something a user would think of specifying in the
whitelist). For a versioned string, the user could instead specify
'commercial_foo_1.2', which would turn into 'commercial_foo_1.2_foo',
but which would as expected allow the user to pick up this package
along with anything else 'commercial' by specifying 'commercial' in
the whitelist, or anything with a 'commercial_foo' license regardless
of version by using 'commercial_foo' in the whitelist, or
'commercial_foo_1.1' to be completely specific about package and
version.
The current behavior of COMMERCIAL_LICENSE is replicated as mentioned
above by having the current set of COMMERCIAL_LICENSE flags
implemented using LICENSE_FLAGS = "commercial".
That being the case, the current COMMERCIAL_LICENSE can equivalently
be specified in the new scheme by putting the below in local.conf:
# This is a list of packages that require a commercial license to ship
# product. If shipped as part of an image these packages may have
# implications so they are disabled by default. To enable them,
# un-comment the below as appropriate.
#LICENSE_FLAGS_WHITELIST = "commercial_gst-fluendo-mp3 \
# commercial_gst-openmax \
# commercial_gst-plugins-ugly \
# commercial_lame \
# commercial_libmad \
# commercial_libomxil \
# commercial_mpeg2dec \
# commercial_qmmp"
The above allows all of the current COMMERCIAL_LICENSE packages in -
to disallow a particular package from appearing in the image, simply
remove it from the whitelist. To allow them all in, you could also
specify LICENSE_FLAGS_WHITELIST = "commercial".
(From OE-Core rev: a2760661b8c7a4a1b6f2e556853b3a9ae38cbcb5)
Signed-off-by: Tom Zanussi <tom.zanussi@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2011-12-31 19:06:39 +00:00
|
|
|
aren't whitelisted.
|
|
|
|
|
2013-11-13 14:32:45 +00:00
|
|
|
If it does, it returns the first LICENSE_FLAGS item missing from the
|
|
|
|
whitelist, or all of the LICENSE_FLAGS if there is no whitelist.
|
license.bbclass: add support for LICENSE_FLAGS
LICENSE_FLAGS are a per-recipe replacement for the COMMERCIAL_LICENSE
mechanism.
In the COMMERCIAL_LICENSE mechanism, any package name mentioned in the
global COMMERCIAL_LICENSE list is 'blacklisted' from being included in
an image. To allow the blacklisted package into the image, the
corresponding packages need to be removed from the COMMERCIAL_LICENSE
list. This mechanism relies on a global list defined in
default-distrovars.inc.
The LICENSE_FLAGS mechanism essentially implements the same thing but
turns the global blacklist into a per-recipe whitelist. Any recipe
can optionally define one or more 'license flags'; if defined, each of
the license flags defined for a recipe must have matching entries in a
global LICENSE_FLAGS_WHITELIST variable.
The definition of 'matching' is simple, but there are a couple things
users need to know in order to correctly and effectively use it.
Before we test a flag against the whitelist, we append _${PN} to it,
thus automatically making each LICENSE_FLAG recipe-specific. We then
try to match that string against the whitelist. So if the user
specifies LICENSE_FLAGS = 'commercial' for recipe 'foo', the string
'commercial_foo' should be specified in the whitelist in order for it
to match.
However, the user can also broaden the match by putting any
'_'-separated beginning subset of a LICENSE_FLAG in the whitelist,
which will also match e.g. simply specifying 'commercial' in the
whitelist would match any expanded LICENSE_FLAG starting with
'commercial' such as 'commercial_foo' and 'commercial_bar' which are
the strings that would have been automatically generated if those
recipes had simply specified LICENSE_FLAGS = 'commercial'
This allows for a range of specificity for the items in the whitelist,
from more general to perfectly specific. So users have the choice of
exhaustively enumerating each license flag in the whitelist to allow
only those specific recipes into the image, or of using a more general
string to pick up anything matching just the first component(s).
Note that this scheme works even if the flag already has _pn appended
- the extra _pn is redundant, but doesn't affect the outcome e.g. a
license flag of 'commercial_1.2_foo' would turn into
'commercial_1.2_foo_foo' and would match both the general 'commercial'
and the specific 'commercial_1.2_foo' as expected (it would also match
commercial_1.2_foo_foo' and 'commercial_1.2', which don't make much
sense as far as something a user would think of specifying in the
whitelist). For a versioned string, the user could instead specify
'commercial_foo_1.2', which would turn into 'commercial_foo_1.2_foo',
but which would as expected allow the user to pick up this package
along with anything else 'commercial' by specifying 'commercial' in
the whitelist, or anything with a 'commercial_foo' license regardless
of version by using 'commercial_foo' in the whitelist, or
'commercial_foo_1.1' to be completely specific about package and
version.
The current behavior of COMMERCIAL_LICENSE is replicated as mentioned
above by having the current set of COMMERCIAL_LICENSE flags
implemented using LICENSE_FLAGS = "commercial".
That being the case, the current COMMERCIAL_LICENSE can equivalently
be specified in the new scheme by putting the below in local.conf:
# This is a list of packages that require a commercial license to ship
# product. If shipped as part of an image these packages may have
# implications so they are disabled by default. To enable them,
# un-comment the below as appropriate.
#LICENSE_FLAGS_WHITELIST = "commercial_gst-fluendo-mp3 \
# commercial_gst-openmax \
# commercial_gst-plugins-ugly \
# commercial_lame \
# commercial_libmad \
# commercial_libomxil \
# commercial_mpeg2dec \
# commercial_qmmp"
The above allows all of the current COMMERCIAL_LICENSE packages in -
to disallow a particular package from appearing in the image, simply
remove it from the whitelist. To allow them all in, you could also
specify LICENSE_FLAGS_WHITELIST = "commercial".
(From OE-Core rev: a2760661b8c7a4a1b6f2e556853b3a9ae38cbcb5)
Signed-off-by: Tom Zanussi <tom.zanussi@intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
2011-12-31 19:06:39 +00:00
|
|
|
|
|
|
|
If everything is is properly whitelisted, it returns None.
|
|
|
|
"""
|
|
|
|
|
|
|
|
def license_flag_matches(flag, whitelist, pn):
|
|
|
|
"""
|
|
|
|
Return True if flag matches something in whitelist, None if not.
|
|
|
|
|
|
|
|
Before we test a flag against the whitelist, we append _${PN}
|
|
|
|
to it. We then try to match that string against the
|
|
|
|
whitelist. This covers the normal case, where we expect
|
|
|
|
LICENSE_FLAGS to be a simple string like 'commercial', which
|
|
|
|
the user typically matches exactly in the whitelist by
|
|
|
|
explicitly appending the package name e.g 'commercial_foo'.
|
|
|
|
If we fail the match however, we then split the flag across
|
|
|
|
'_' and append each fragment and test until we either match or
|
|
|
|
run out of fragments.
|
|
|
|
"""
|
|
|
|
flag_pn = ("%s_%s" % (flag, pn))
|
|
|
|
for candidate in whitelist:
|
|
|
|
if flag_pn == candidate:
|
|
|
|
return True
|
|
|
|
|
|
|
|
flag_cur = ""
|
|
|
|
flagments = flag_pn.split("_")
|
|
|
|
flagments.pop() # we've already tested the full string
|
|
|
|
for flagment in flagments:
|
|
|
|
if flag_cur:
|
|
|
|
flag_cur += "_"
|
|
|
|
flag_cur += flagment
|
|
|
|
for candidate in whitelist:
|
|
|
|
if flag_cur == candidate:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
def all_license_flags_match(license_flags, whitelist):
|
|
|
|
""" Return first unmatched flag, None if all flags match """
|
|
|
|
pn = d.getVar('PN', True)
|
|
|
|
split_whitelist = whitelist.split()
|
|
|
|
for flag in license_flags.split():
|
|
|
|
if not license_flag_matches(flag, split_whitelist, pn):
|
|
|
|
return flag
|
|
|
|
return None
|
|
|
|
|
|
|
|
license_flags = d.getVar('LICENSE_FLAGS', True)
|
|
|
|
if license_flags:
|
|
|
|
whitelist = d.getVar('LICENSE_FLAGS_WHITELIST', True)
|
|
|
|
if not whitelist:
|
|
|
|
return license_flags
|
|
|
|
unmatched_flag = all_license_flags_match(license_flags, whitelist)
|
|
|
|
if unmatched_flag:
|
|
|
|
return unmatched_flag
|
|
|
|
return None
|
|
|
|
|
2011-02-03 12:33:18 +00:00
|
|
|
SSTATETASKS += "do_populate_lic"
|
|
|
|
do_populate_lic[sstate-inputdirs] = "${LICSSTATEDIR}"
|
|
|
|
do_populate_lic[sstate-outputdirs] = "${LICENSE_DIRECTORY}/"
|
|
|
|
|
2014-01-27 01:41:31 +00:00
|
|
|
ROOTFS_POSTPROCESS_COMMAND_prepend = "write_package_manifest; license_create_manifest; "
|
2011-12-03 23:16:15 +00:00
|
|
|
|
2011-02-03 12:33:18 +00:00
|
|
|
python do_populate_lic_setscene () {
|
2012-07-11 17:33:43 +00:00
|
|
|
sstate_setscene(d)
|
2011-02-03 12:33:18 +00:00
|
|
|
}
|
|
|
|
addtask do_populate_lic_setscene
|