Patchwork [2/2] license.bbclass: package license texts to PN-lic when LICENSE_CREATE_PACKAGE is enabled

login
register
mail settings
Submitter Martin Jansa
Date Jan. 17, 2013, 11:49 a.m.
Message ID <abc88e3324899fe1d3a58b7031cb7f687aa93075.1358423316.git.Martin.Jansa@gmail.com>
Download mbox | patch
Permalink /patch/42789/
State Accepted
Commit dc78ef91a2bf01efb8028c9afbe69e506e016265
Headers show

Comments

Martin Jansa - Jan. 17, 2013, 11:49 a.m.
[YOCTO #3743]

Signed-off-by: Martin Jansa <Martin.Jansa@gmail.com>
---
 meta/classes/license.bbclass | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

Patch

diff --git a/meta/classes/license.bbclass b/meta/classes/license.bbclass
index 63d081f..22e6c56 100644
--- a/meta/classes/license.bbclass
+++ b/meta/classes/license.bbclass
@@ -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: