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