Enable initrd creation
[scm/bb/meta-tizen.git] / meta-tizen-common-base / classes / metatizen.bbclass
1
2 DIRFILES = "1"
3
4
5
6 python () {
7     if bb.data.inherits_class('rootfs_rpm', d):
8         rootfsdepends = d.getVarFlag("do_rootfs", "depends", True)
9         rootfsdepends = rootfsdepends.replace("rpmresolve-native:do_populate_sysroot", "")
10         d.setVarFlag("do_rootfs", "depends", rootfsdepends)
11 }
12
13 # MANIFESTFILES_<pn> is the Tizen Smack .manifest file to be used for a binary .rpm.
14 # It must be part of the source tree (either at the root or in a sub-directory)
15 # or get created there during configure. Out-of-tree compilation is not supported.
16
17 # Enable extra code for the binary .rpm spec files which injects the %manifest
18 # lines for each package.
19 RPM_EXTRA_PKGDATA = "1"
20 def package_rpm_extra_pkgdata(splitname, spec_file, d):
21     if d.getVar('MANIFESTFILES', True):
22         # Must use .manifest files at the location where tizen_copy_manifest() put it.
23         spec_file.append('%%manifest ../packages-split/%s' % (d.getVar('MANIFESTFILES', True)))
24     else:
25         fetch = bb.fetch2.Fetch([], d)
26         for url in fetch.urls:
27             local = fetch.localpath(url)
28             base = os.path.basename(local)
29             if base.endswith('.manifest.in'):
30                 manifest = base[:-3]
31             else:
32                 manifest = base
33             if manifest.endswith('.manifest'):
34                  urldata = fetch.ud[url]
35                  if 'pkg' in urldata.parm:
36                      pkg = urldata.parm['pkg'].split(',')
37                      enabled = splitname in pkg or not pkg
38                  else:
39                      enabled = True
40                  if enabled:
41                      # Optionally replace placeholders with content of the corresponding variables,
42                      # otherwise just copy to a place where rpm can find it. Absolute paths
43                      # refering to a file on the host do not work, because rpm interprets them
44                      # relative to the build dir.
45                      content = open(local).read()
46                      if base != manifest:
47                          import re
48                          def replace(m):
49                              word = m.group(1)
50                              # Must be a known variable.
51                              return d.getVar(word, True)
52                          content = re.sub('@([a-zA-Z0-9_]+)@', replace, content)
53                      # Create relative to _builddir = $S, see package_rpm.bbclass/do_package_rpm ().
54                      dvar = d.getVar('S', True)
55                      copy = os.path.join(dvar, manifest)
56                      print '***', copy
57                      if not os.path.exists(dvar):
58                          os.makedirs(dvar)
59                      f = open(copy, 'w')
60                      f.write(content)
61                      f.close()
62                      spec_file.append('%%manifest %s' % manifest)
63                      break
64
65 # Copies manifest files from source to packages-split. Necessary because
66 # source is not always available during packaging (for example, when
67 # using sstate), only $PKGDEST is.
68 PACKAGESPLITFUNCS_append = " tizen_copy_manifest"
69 python tizen_copy_manifest () {
70     dest = d.getVar('S', True)
71     dvar = d.getVar('PKGDEST', True)
72
73     packages = d.getVar('PACKAGES', True)
74     for pkg in packages.split():
75         manifest_path=d.getVar('MANIFESTFILES_%s' % pkg, True)
76         if manifest_path:
77             manifest_dir = os.path.dirname(manifest_path)
78
79             if manifest_dir:
80                 cmd = 'mkdir -p %s/%s' % (dvar,manifest_dir)
81                 (retval, output) = oe.utils.getstatusoutput(cmd)
82                 if retval:
83                     bb.fatal("directory failed to be created with exit code %s (cmd was %s)%s" % (retval, cmd, ":\n%s" % output if output else ""))
84
85             cmd = 'cp %s/%s %s/%s' % (dest, manifest_path , dvar,manifest_dir)
86
87             (retval, output) = oe.utils.getstatusoutput(cmd)
88             if retval:
89                 bb.fatal("file copy failed with exit code %s (cmd was %s)%s" % (retval, cmd, ":\n%s" % output if output else ""))
90 }