Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | inherit package |
| 2 | |
| 3 | IMAGE_PKGTYPE ?= "tar" |
| 4 | |
| 5 | python do_package_tar () { |
| 6 | import subprocess |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 7 | |
| 8 | oldcwd = os.getcwd() |
| 9 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 10 | workdir = d.getVar('WORKDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | if not workdir: |
| 12 | bb.error("WORKDIR not defined, unable to package") |
| 13 | return |
| 14 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 15 | outdir = d.getVar('DEPLOY_DIR_TAR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 16 | if not outdir: |
| 17 | bb.error("DEPLOY_DIR_TAR not defined, unable to package") |
| 18 | return |
| 19 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 20 | dvar = d.getVar('D') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 21 | if not dvar: |
| 22 | bb.error("D not defined, unable to package") |
| 23 | return |
| 24 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 25 | packages = d.getVar('PACKAGES') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | if not packages: |
| 27 | bb.debug(1, "PACKAGES not defined, nothing to package") |
| 28 | return |
| 29 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 30 | pkgdest = d.getVar('PKGDEST') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 31 | |
| 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 Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 41 | |
| 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 Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 48 | bb.note("Not creating empty archive for %s-%s-%s" % (pkg, localdata.getVar('PKGV'), localdata.getVar('PKGR'))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 49 | 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 Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 54 | |
| 55 | os.chdir(oldcwd) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | python () { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 59 | if d.getVar('PACKAGES') != '': |
| 60 | deps = (d.getVarFlag('do_package_write_tar', 'depends') or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 61 | 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 | |
| 68 | python do_package_write_tar () { |
| 69 | bb.build.exec_func("read_subpackage_metadata", d) |
| 70 | bb.build.exec_func("do_package_tar", d) |
| 71 | } |
| 72 | do_package_write_tar[dirs] = "${D}" |
| 73 | addtask package_write_tar before do_build after do_packagedata do_package |