Packaging license texts in PN
cover Packaging license texts in PN
The following changes since commit 0ada16fe509d9a8608c05d16666243c8ebe4d3b3:
apmd: fix license segment md5sum boundary (2013-01-16 11:54:47 +0000)
are available in the git repository at:
git://git.openembedded.org/openembedded-core-contrib jansa/license-pn
http://cgit.openembedded.org/cgit.cgi/openembedded-core-contrib/log/?h=jansa/license-pn
Martin Jansa (2):
license.bbclass: extract functionality to find license files to
separate function
license.bbclass: package license texts to PN-lic when
LICENSE_CREATE_PACKAGE is enabled
meta/classes/license.bbclass | 78 ++++++++++++++++++++++++++++++++++---------- 1 file changed, 60 insertions(+), 18 deletions(-)
Signature · 1 line
1.8.1.1
PATCH 1/2 license.bbclass: extract functionality to find license files to separate function
* move it from do_populate_lic to find_license_files so we can reuse it to populate license in package itself
[YOCTO #3743]
--- meta/classes/license.bbclass | 44 ++++++++++++++++++++++++++------------------ 1 file changed, 26 insertions(+), 18 deletions(-)
meta/classes/license.bbclass +26 -18
@@ -88,6 +88,25 @@ python do_populate_lic() { """ Populate LICENSE_DIRECTORY with licenses. """ + 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) +} + +def copy_license_files(lic_files_paths, destdir): + bb.mkdirhier(destdir) + for (basename, path) in lic_files_paths: + ret = bb.copyfile(path, os.path.join(destdir, basename)) + # If the copy didn't occur, something horrible went wrong and we fail out + if not ret: + bb.warn("%s could not be copied for some reason. It may not exist. WARN for now." % path) + +def find_license_files(d): + """ + Creates list of files used in LIC_FILES_CHKSUM and generic LICENSE files. + """ import shutil import oe.license
@@ -108,12 +127,12 @@ python do_populate_lic() { # All the license files for the package lic_files = d.getVar('LIC_FILES_CHKSUM', True) pn = d.getVar('PN', True) - # The base directory we wrangle licenses to - destdir = os.path.join(d.getVar('LICSSTATEDIR', True), pn) # 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) + # List of basename, path tuples + lic_files_paths = [] license_source_dirs = [] license_source_dirs.append(generic_directory) try:
@@ -159,20 +178,12 @@ python do_populate_lic() { # 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) - bb.copyfile(os.path.join(license_source, spdx_generic), os.path.join(os.path.join(d.getVar('LICSSTATEDIR', True), pn), "generic_" + license_type)) - if not os.path.isfile(os.path.join(os.path.join(d.getVar('LICSSTATEDIR', True), pn), "generic_" + license_type)): - # If the copy didn't occur, something horrible went wrong and we fail out - bb.warn("%s for %s could not be copied for some reason. It may not exist. WARN for now." % (spdx_generic, pn)) + lic_files_paths.append(("generic_" + license_type, os.path.join(license_source, spdx_generic))) 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 - try: - bb.mkdirhier(destdir) - except: - pass - if not generic_directory: raise bb.build.FuncFailed("COMMON_LICENSE_DIR is unset. Please set this in your distro config")
@@ -180,16 +191,13 @@ python do_populate_lic() { # 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.") - return True + return lic_files_paths for url in lic_files.split(): (type, host, path, user, pswd, parm) = bb.decodeurl(url) - # We want the license file to be copied into the destination + # We want the license filename and path srclicfile = os.path.join(srcdir, path) - ret = bb.copyfile(srclicfile, os.path.join(destdir, os.path.basename(path))) - # If the copy didn't occur, something horrible went wrong and we fail out - if not ret: - bb.warn("%s could not be copied for some reason. It may not exist. WARN for now." % srclicfile) + lic_files_paths.append((os.path.basename(path), srclicfile)) v = FindVisitor() try:
@@ -199,7 +207,7 @@ python do_populate_lic() { except SyntaxError: bb.warn("%s: Failed to parse it's LICENSE field." % (d.getVar('PF', True))) -} + return lic_files_paths def return_spdx(d, license): """
Signature · 1 line
1.8.1.1
PATCH 2/2 license.bbclass: package license texts to PN-lic when LICENSE_CREATE_PACKAGE is enabled
In reply to Martin Jansa[YOCTO #3743]
--- meta/classes/license.bbclass | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+)
meta/classes/license.bbclass +34 -0
@@ -6,6 +6,11 @@ LICENSE_DIRECTORY ??= "${DEPLOY_DIR}/licenses" LICSSTATEDIR = "${WORKDIR}/license-destdir/" +# Create extra package with license texts and add it to RRECOMMENDS_${PN} +LICENSE_CREATE_PACKAGE ??= "0" +LICENSE_PACKAGE_SUFFIX ??= "-lic" +LICENSE_FILES_DIRECTORY ??= "${datadir}/licenses/" + addtask populate_lic after do_patch before do_build do_populate_lic[dirs] = "${LICSSTATEDIR}/${PN}" do_populate_lic[cleandirs] = "${LICSSTATEDIR}"
@@ -95,6 +100,35 @@ python do_populate_lic() { copy_license_files(lic_files_paths, destdir) } +# it would be better to copy them in do_install_append, but find_license_filesa is python +python perform_packagecopy_prepend () { + enabled = d.getVar('LICENSE_CREATE_PACKAGE', True) + 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)) + def copy_license_files(lic_files_paths, destdir): bb.mkdirhier(destdir) for (basename, path) in lic_files_paths:
Signature · 1 line
1.8.1.1