summaryrefslogtreecommitdiffstats
path: root/meta/classes/package_tar.bbclass
diff options
context:
space:
mode:
Diffstat (limited to 'meta/classes/package_tar.bbclass')
-rw-r--r--meta/classes/package_tar.bbclass99
1 files changed, 99 insertions, 0 deletions
diff --git a/meta/classes/package_tar.bbclass b/meta/classes/package_tar.bbclass
new file mode 100644
index 0000000000..359e35f113
--- /dev/null
+++ b/meta/classes/package_tar.bbclass
@@ -0,0 +1,99 @@
1inherit package
2
3PACKAGEFUNCS += "do_package_tar"
4
5python package_tar_fn () {
6 import os
7 from bb import data
8 fn = os.path.join(bb.data.getVar('DEPLOY_DIR_TAR', d), "%s-%s-%s.tar.gz" % (bb.data.getVar('PKG', d), bb.data.getVar('PV', d), bb.data.getVar('PR', d)))
9 fn = bb.data.expand(fn, d)
10 bb.data.setVar('PKGFN', fn, d)
11}
12
13python package_tar_install () {
14 import os, sys
15 pkg = bb.data.getVar('PKG', d, 1)
16 pkgfn = bb.data.getVar('PKGFN', d, 1)
17 rootfs = bb.data.getVar('IMAGE_ROOTFS', d, 1)
18
19 if None in (pkg,pkgfn,rootfs):
20 bb.error("missing variables (one or more of PKG, PKGFN, IMAGEROOTFS)")
21 raise bb.build.FuncFailed
22 try:
23 bb.mkdirhier(rootfs)
24 os.chdir(rootfs)
25 except OSError:
26 (type, value, traceback) = sys.exc_info()
27 print value
28 raise bb.build.FuncFailed
29
30 if not os.access(pkgfn, os.R_OK):
31 bb.debug(1, "%s does not exist, skipping" % pkgfn)
32 raise bb.build.FuncFailed
33
34 ret = os.system('zcat %s | tar -xf -' % pkgfn)
35 if ret != 0:
36 raise bb.build.FuncFailed
37}
38
39python do_package_tar () {
40 workdir = bb.data.getVar('WORKDIR', d, 1)
41 if not workdir:
42 bb.error("WORKDIR not defined, unable to package")
43 return
44
45 import os # path manipulations
46 outdir = bb.data.getVar('DEPLOY_DIR_TAR', d, 1)
47 if not outdir:
48 bb.error("DEPLOY_DIR_TAR not defined, unable to package")
49 return
50 bb.mkdirhier(outdir)
51
52 dvar = bb.data.getVar('D', d, 1)
53 if not dvar:
54 bb.error("D not defined, unable to package")
55 return
56 bb.mkdirhier(dvar)
57
58 packages = bb.data.getVar('PACKAGES', d, 1)
59 if not packages:
60 bb.debug(1, "PACKAGES not defined, nothing to package")
61 return
62
63 for pkg in packages.split():
64 localdata = bb.data.createCopy(d)
65 root = "%s/install/%s" % (workdir, pkg)
66
67 bb.data.setVar('ROOT', '', localdata)
68 bb.data.setVar('ROOT_%s' % pkg, root, localdata)
69 bb.data.setVar('PKG', pkg, localdata)
70
71 overrides = bb.data.getVar('OVERRIDES', localdata)
72 if not overrides:
73 raise bb.build.FuncFailed('OVERRIDES not defined')
74 overrides = bb.data.expand(overrides, localdata)
75 bb.data.setVar('OVERRIDES', '%s:%s' % (overrides, pkg), localdata)
76
77 bb.data.update_data(localdata)
78# stuff
79 root = bb.data.getVar('ROOT', localdata)
80 bb.mkdirhier(root)
81 basedir = os.path.dirname(root)
82 pkgoutdir = outdir
83 bb.mkdirhier(pkgoutdir)
84 bb.build.exec_func('package_tar_fn', localdata)
85 tarfn = bb.data.getVar('PKGFN', localdata, 1)
86# if os.path.exists(tarfn):
87# del localdata
88# continue
89 os.chdir(root)
90 from glob import glob
91 if not glob('*'):
92 bb.note("Not creating empty archive for %s-%s-%s" % (pkg, bb.data.getVar('PV', localdata, 1), bb.data.getVar('PR', localdata, 1)))
93 continue
94 ret = os.system("tar -czvf %s %s" % (tarfn, '.'))
95 if ret != 0:
96 bb.error("Creation of tar %s failed." % tarfn)
97# end stuff
98 del localdata
99}