manifests: add support for SRC_URI 43/30743/2
authorPatrick Ohly <patrick.ohly@intel.com>
Mon, 24 Nov 2014 20:15:38 +0000 (21:15 +0100)
committerronan(Eurogiciel) Le Martret <ronan.lemartret@open.eurogiciel.org>
Mon, 1 Dec 2014 13:29:02 +0000 (05:29 -0800)
MANIFESTFILES assumes that the file comes out of the source or build
process. The new SRC_URI support for files ending in .manifest or
.manifest.in makes it possible to add manifest files as pure packaging
meta data.

The "pkg" parameter determines which package the manifest file is used
for. If not set or empty, it is used for all. If set, the value is a
comma-separated list of package names. The first suitable manifest
file is used. Fake example file_%.bbappend:

SRC_URI += "file://libmagic.manifest.in;pkg=libmagic,libmagic-data file://file.manifest"
FILESEXTRAPATHS_prepend := "${THISDIR}/${PN}:"

When turning a .manifest.in file into .manifest, @[a-zA-Z0-9]+@ will
get replaced by the value of the corresponding Bitbake variable (for
example, "bindir").

This could also cover Tizen multi-user variables
(https://wiki.tizen.org/wiki/Multi-user_Platform_Metadata) if those were
added to the active distro or build conf.

Change-Id: I33e49ea4e97670a70bc06bff21a265272a48626e
Signed-off-by: Patrick Ohly <patrick.ohly@intel.com>
meta-tizen-common-base/classes/metatizen.bbclass

index 3977f47..5f77686 100644 (file)
@@ -25,6 +25,46 @@ def package_rpm_extra_pkgdata(splitname, spec_file, d):
     if d.getVar('MANIFESTFILES', True):
         # Must use .manifest files at the location where tizen_copy_manifest() put it.
         spec_file.append('%%manifest ../packages-split/%s' % (d.getVar('MANIFESTFILES', True)))
+    else:
+        fetch = bb.fetch2.Fetch([], d)
+        for url in fetch.urls:
+            local = fetch.localpath(url)
+            base = os.path.basename(local)
+            if base.endswith('.manifest.in'):
+                manifest = base[:-3]
+            else:
+                manifest = base
+            if manifest.endswith('.manifest'):
+                 urldata = fetch.ud[url]
+                 if 'pkg' in urldata.parm:
+                     pkg = urldata.parm['pkg'].split(',')
+                     enabled = splitname in pkg or not pkg
+                 else:
+                     enabled = True
+                 if enabled:
+                     # Optionally replace placeholders with content of the corresponding variables,
+                     # otherwise just copy to a place where rpm can find it. Absolute paths
+                     # refering to a file on the host do not work, because rpm interprets them
+                     # relative to the build dir.
+                     content = open(local).read()
+                     if base != manifest:
+                         import re
+                         def replace(m):
+                             word = m.group(1)
+                             # Must be a known variable.
+                             return d.getVar(word, True)
+                         content = re.sub('@([a-zA-Z0-9_]+)@', replace, content)
+                     # Create relative to _builddir = $S, see package_rpm.bbclass/do_package_rpm ().
+                     dvar = d.getVar('S', True)
+                     copy = os.path.join(dvar, manifest)
+                     print '***', copy
+                     if not os.path.exists(dvar):
+                         os.makedirs(dvar)
+                     f = open(copy, 'w')
+                     f.write(content)
+                     f.close()
+                     spec_file.append('%%manifest %s' % manifest)
+                     break
 
 # Copies manifest files from source to packages-split. Necessary because
 # source is not always available during packaging (for example, when