blob: ce3ab4c8e226ac16317131a5c475fa928d6cdbd2 [file] [log] [blame]
Patrick Williamsc124f4f2015-09-15 14:41:29 -05001inherit package
2
3IMAGE_PKGTYPE ?= "tar"
4
5python do_package_tar () {
6 import subprocess
Patrick Williamsc0f7c042017-02-23 20:41:17 -06007
8 oldcwd = os.getcwd()
9
Brad Bishop6e60e8b2018-02-01 10:27:11 -050010 workdir = d.getVar('WORKDIR')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050011 if not workdir:
12 bb.error("WORKDIR not defined, unable to package")
13 return
14
Brad Bishop6e60e8b2018-02-01 10:27:11 -050015 outdir = d.getVar('DEPLOY_DIR_TAR')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050016 if not outdir:
17 bb.error("DEPLOY_DIR_TAR not defined, unable to package")
18 return
19
Brad Bishop6e60e8b2018-02-01 10:27:11 -050020 dvar = d.getVar('D')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050021 if not dvar:
22 bb.error("D not defined, unable to package")
23 return
24
Brad Bishop6e60e8b2018-02-01 10:27:11 -050025 packages = d.getVar('PACKAGES')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026 if not packages:
27 bb.debug(1, "PACKAGES not defined, nothing to package")
28 return
29
Brad Bishop6e60e8b2018-02-01 10:27:11 -050030 pkgdest = d.getVar('PKGDEST')
Patrick Williamsc124f4f2015-09-15 14:41:29 -050031
32 bb.utils.mkdirhier(outdir)
33 bb.utils.mkdirhier(dvar)
34
35 for pkg in packages.split():
36 localdata = bb.data.createCopy(d)
37 root = "%s/%s" % (pkgdest, pkg)
38
39 overrides = localdata.getVar('OVERRIDES', False)
40 localdata.setVar('OVERRIDES', '%s:%s' % (overrides, pkg))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050041
42 bb.utils.mkdirhier(root)
43 basedir = os.path.dirname(root)
44 tarfn = localdata.expand("${DEPLOY_DIR_TAR}/${PKG}-${PKGV}-${PKGR}.tar.gz")
45 os.chdir(root)
46 dlist = os.listdir(root)
47 if not dlist:
Brad Bishop6e60e8b2018-02-01 10:27:11 -050048 bb.note("Not creating empty archive for %s-%s-%s" % (pkg, localdata.getVar('PKGV'), localdata.getVar('PKGR')))
Patrick Williamsc124f4f2015-09-15 14:41:29 -050049 continue
50 args = "tar -cz --exclude=CONTROL --exclude=DEBIAN -f".split()
51 ret = subprocess.call(args + [tarfn] + dlist)
52 if ret != 0:
53 bb.error("Creation of tar %s failed." % tarfn)
Patrick Williamsc0f7c042017-02-23 20:41:17 -060054
55 os.chdir(oldcwd)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050056}
57
58python () {
Brad Bishop6e60e8b2018-02-01 10:27:11 -050059 if d.getVar('PACKAGES') != '':
60 deps = (d.getVarFlag('do_package_write_tar', 'depends') or "").split()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050061 deps.append('tar-native:do_populate_sysroot')
62 deps.append('virtual/fakeroot-native:do_populate_sysroot')
63 d.setVarFlag('do_package_write_tar', 'depends', " ".join(deps))
64 d.setVarFlag('do_package_write_tar', 'fakeroot', "1")
65}
66
67
68python do_package_write_tar () {
69 bb.build.exec_func("read_subpackage_metadata", d)
70 bb.build.exec_func("do_package_tar", d)
71}
72do_package_write_tar[dirs] = "${D}"
73addtask package_write_tar before do_build after do_packagedata do_package