Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # |
| 2 | # Copyright 2006-2008 OpenedHand Ltd. |
| 3 | # |
| 4 | |
| 5 | inherit package |
| 6 | |
| 7 | IMAGE_PKGTYPE ?= "deb" |
| 8 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 9 | DPKG_ARCH ?= "${@debian_arch_map(d.getVar('TARGET_ARCH'), d.getVar('TUNE_FEATURES'))}" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 10 | DPKG_ARCH[vardepvalue] = "${DPKG_ARCH}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 11 | |
| 12 | PKGWRITEDIRDEB = "${WORKDIR}/deploy-debs" |
| 13 | |
| 14 | APTCONF_TARGET = "${WORKDIR}" |
| 15 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 16 | APT_ARGS = "${@['', '--no-install-recommends'][d.getVar("NO_RECOMMENDATIONS") == "1"]}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 17 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 18 | def debian_arch_map(arch, tune): |
| 19 | tune_features = tune.split() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 20 | if arch == "allarch": |
| 21 | return "all" |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 22 | if arch in ["i586", "i686"]: |
| 23 | return "i386" |
| 24 | if arch == "x86_64": |
| 25 | if "mx32" in tune_features: |
| 26 | return "x32" |
| 27 | return "amd64" |
| 28 | if arch.startswith("mips"): |
| 29 | endian = ["el", ""]["bigendian" in tune_features] |
| 30 | if "n64" in tune_features: |
| 31 | return "mips64" + endian |
| 32 | if "n32" in tune_features: |
| 33 | return "mipsn32" + endian |
| 34 | return "mips" + endian |
| 35 | if arch == "powerpc": |
| 36 | return arch + ["", "spe"]["spe" in tune_features] |
| 37 | if arch == "aarch64": |
| 38 | return "arm64" |
| 39 | if arch == "arm": |
| 40 | return arch + ["el", "hf"]["callconvention-hard" in tune_features] |
| 41 | return arch |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 42 | |
| 43 | python do_package_deb () { |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 44 | |
| 45 | import multiprocessing |
| 46 | import traceback |
| 47 | |
| 48 | class DebianWritePkgProcess(multiprocessing.Process): |
| 49 | def __init__(self, *args, **kwargs): |
| 50 | multiprocessing.Process.__init__(self, *args, **kwargs) |
| 51 | self._pconn, self._cconn = multiprocessing.Pipe() |
| 52 | self._exception = None |
| 53 | |
| 54 | def run(self): |
| 55 | try: |
| 56 | multiprocessing.Process.run(self) |
| 57 | self._cconn.send(None) |
| 58 | except Exception as e: |
| 59 | tb = traceback.format_exc() |
| 60 | self._cconn.send((e, tb)) |
| 61 | |
| 62 | @property |
| 63 | def exception(self): |
| 64 | if self._pconn.poll(): |
| 65 | self._exception = self._pconn.recv() |
| 66 | return self._exception |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 67 | |
| 68 | oldcwd = os.getcwd() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 69 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 70 | packages = d.getVar('PACKAGES') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 71 | if not packages: |
| 72 | bb.debug(1, "PACKAGES not defined, nothing to package") |
| 73 | return |
| 74 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 75 | tmpdir = d.getVar('TMPDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 76 | if os.access(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"),os.R_OK): |
| 77 | os.unlink(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN")) |
| 78 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 79 | max_process = int(d.getVar("BB_NUMBER_THREADS") or os.cpu_count() or 1) |
| 80 | launched = [] |
| 81 | error = None |
| 82 | pkgs = packages.split() |
| 83 | while not error and pkgs: |
| 84 | if len(launched) < max_process: |
| 85 | p = DebianWritePkgProcess(target=deb_write_pkg, args=(pkgs.pop(), d)) |
| 86 | p.start() |
| 87 | launched.append(p) |
| 88 | for q in launched: |
| 89 | # The finished processes are joined when calling is_alive() |
| 90 | if not q.is_alive(): |
| 91 | launched.remove(q) |
| 92 | if q.exception: |
| 93 | error, traceback = q.exception |
| 94 | break |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 95 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 96 | for p in launched: |
| 97 | p.join() |
| 98 | |
| 99 | os.chdir(oldcwd) |
| 100 | |
| 101 | if error: |
| 102 | raise error |
| 103 | } |
| 104 | do_package_deb[vardeps] += "deb_write_pkg" |
| 105 | do_package_deb[vardepsexclude] = "BB_NUMBER_THREADS" |
| 106 | |
| 107 | def deb_write_pkg(pkg, d): |
| 108 | import re, copy |
| 109 | import textwrap |
| 110 | import subprocess |
| 111 | import collections |
| 112 | import codecs |
| 113 | |
| 114 | outdir = d.getVar('PKGWRITEDIRDEB') |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 115 | pkgdest = d.getVar('PKGDEST') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 116 | |
| 117 | def cleanupcontrol(root): |
| 118 | for p in ['CONTROL', 'DEBIAN']: |
| 119 | p = os.path.join(root, p) |
| 120 | if os.path.exists(p): |
| 121 | bb.utils.prunedir(p) |
| 122 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 123 | localdata = bb.data.createCopy(d) |
| 124 | root = "%s/%s" % (pkgdest, pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 125 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 126 | lf = bb.utils.lockfile(root + ".lock") |
| 127 | try: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 128 | |
| 129 | localdata.setVar('ROOT', '') |
| 130 | localdata.setVar('ROOT_%s' % pkg, root) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 131 | pkgname = localdata.getVar('PKG_%s' % pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 132 | if not pkgname: |
| 133 | pkgname = pkg |
| 134 | localdata.setVar('PKG', pkgname) |
| 135 | |
| 136 | localdata.setVar('OVERRIDES', d.getVar("OVERRIDES", False) + ":" + pkg) |
| 137 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 138 | basedir = os.path.join(os.path.dirname(root)) |
| 139 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 140 | pkgoutdir = os.path.join(outdir, localdata.getVar('PACKAGE_ARCH')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 141 | bb.utils.mkdirhier(pkgoutdir) |
| 142 | |
| 143 | os.chdir(root) |
| 144 | cleanupcontrol(root) |
| 145 | from glob import glob |
| 146 | g = glob('*') |
| 147 | if not g and localdata.getVar('ALLOW_EMPTY', False) != "1": |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 148 | bb.note("Not creating empty archive for %s-%s-%s" % (pkg, localdata.getVar('PKGV'), localdata.getVar('PKGR'))) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 149 | return |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 150 | |
| 151 | controldir = os.path.join(root, 'DEBIAN') |
| 152 | bb.utils.mkdirhier(controldir) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 153 | os.chmod(controldir, 0o755) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 154 | |
| 155 | ctrlfile = codecs.open(os.path.join(controldir, 'control'), 'w', 'utf-8') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 156 | |
| 157 | fields = [] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 158 | pe = d.getVar('PKGE') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 159 | if pe and int(pe) > 0: |
| 160 | fields.append(["Version: %s:%s-%s\n", ['PKGE', 'PKGV', 'PKGR']]) |
| 161 | else: |
| 162 | fields.append(["Version: %s-%s\n", ['PKGV', 'PKGR']]) |
| 163 | fields.append(["Description: %s\n", ['DESCRIPTION']]) |
| 164 | fields.append(["Section: %s\n", ['SECTION']]) |
| 165 | fields.append(["Priority: %s\n", ['PRIORITY']]) |
| 166 | fields.append(["Maintainer: %s\n", ['MAINTAINER']]) |
| 167 | fields.append(["Architecture: %s\n", ['DPKG_ARCH']]) |
| 168 | fields.append(["OE: %s\n", ['PN']]) |
| 169 | fields.append(["PackageArch: %s\n", ['PACKAGE_ARCH']]) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 170 | if d.getVar('HOMEPAGE'): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 171 | fields.append(["Homepage: %s\n", ['HOMEPAGE']]) |
| 172 | |
| 173 | # Package, Version, Maintainer, Description - mandatory |
| 174 | # Section, Priority, Essential, Architecture, Source, Depends, Pre-Depends, Recommends, Suggests, Conflicts, Replaces, Provides - Optional |
| 175 | |
| 176 | |
| 177 | def pullData(l, d): |
| 178 | l2 = [] |
| 179 | for i in l: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 180 | data = d.getVar(i) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 181 | if data is None: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 182 | raise KeyError(i) |
| 183 | if i == 'DPKG_ARCH' and d.getVar('PACKAGE_ARCH') == 'all': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 184 | data = 'all' |
| 185 | elif i == 'PACKAGE_ARCH' or i == 'DPKG_ARCH': |
| 186 | # The params in deb package control don't allow character |
| 187 | # `_', so change the arch's `_' to `-'. Such as `x86_64' |
| 188 | # -->`x86-64' |
| 189 | data = data.replace('_', '-') |
| 190 | l2.append(data) |
| 191 | return l2 |
| 192 | |
| 193 | ctrlfile.write("Package: %s\n" % pkgname) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 194 | if d.getVar('PACKAGE_ARCH') == "all": |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 195 | ctrlfile.write("Multi-Arch: foreign\n") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 196 | # check for required fields |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 197 | for (c, fs) in fields: |
| 198 | # Special behavior for description... |
| 199 | if 'DESCRIPTION' in fs: |
| 200 | summary = localdata.getVar('SUMMARY') or localdata.getVar('DESCRIPTION') or "." |
| 201 | ctrlfile.write('Description: %s\n' % summary) |
| 202 | description = localdata.getVar('DESCRIPTION') or "." |
| 203 | description = textwrap.dedent(description).strip() |
| 204 | if '\\n' in description: |
| 205 | # Manually indent |
| 206 | for t in description.split('\\n'): |
| 207 | ctrlfile.write(' %s\n' % (t.strip() or '.')) |
| 208 | else: |
| 209 | # Auto indent |
| 210 | ctrlfile.write('%s\n' % textwrap.fill(description.strip(), width=74, initial_indent=' ', subsequent_indent=' ')) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 211 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 212 | else: |
| 213 | ctrlfile.write(c % tuple(pullData(fs, localdata))) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 214 | |
| 215 | # more fields |
| 216 | |
| 217 | custom_fields_chunk = get_package_additional_metadata("deb", localdata) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 218 | if custom_fields_chunk: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 219 | ctrlfile.write(custom_fields_chunk) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 220 | ctrlfile.write("\n") |
| 221 | |
| 222 | mapping_rename_hook(localdata) |
| 223 | |
| 224 | def debian_cmp_remap(var): |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 225 | # dpkg does not allow for '(', ')' or ':' in a dependency name |
| 226 | # Replace any instances of them with '__' |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 227 | # |
| 228 | # In debian '>' and '<' do not mean what it appears they mean |
| 229 | # '<' = less or equal |
| 230 | # '>' = greater or equal |
| 231 | # adjust these to the '<<' and '>>' equivalents |
| 232 | # |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame^] | 233 | for dep in list(var.keys()): |
| 234 | if '(' in dep or '/' in dep: |
| 235 | newdep = re.sub(r'[(:)/]', '__', dep) |
| 236 | if newdep.startswith("__"): |
| 237 | newdep = "A" + newdep |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 238 | if newdep != dep: |
| 239 | var[newdep] = var[dep] |
| 240 | del var[dep] |
| 241 | for dep in var: |
| 242 | for i, v in enumerate(var[dep]): |
| 243 | if (v or "").startswith("< "): |
| 244 | var[dep][i] = var[dep][i].replace("< ", "<< ") |
| 245 | elif (v or "").startswith("> "): |
| 246 | var[dep][i] = var[dep][i].replace("> ", ">> ") |
| 247 | |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 248 | rdepends = bb.utils.explode_dep_versions2(localdata.getVar("RDEPENDS") or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 249 | debian_cmp_remap(rdepends) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 250 | for dep in list(rdepends.keys()): |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 251 | if dep == pkg: |
| 252 | del rdepends[dep] |
| 253 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 254 | if '*' in dep: |
| 255 | del rdepends[dep] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 256 | rrecommends = bb.utils.explode_dep_versions2(localdata.getVar("RRECOMMENDS") or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 257 | debian_cmp_remap(rrecommends) |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 258 | for dep in list(rrecommends.keys()): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 259 | if '*' in dep: |
| 260 | del rrecommends[dep] |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 261 | rsuggests = bb.utils.explode_dep_versions2(localdata.getVar("RSUGGESTS") or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 262 | debian_cmp_remap(rsuggests) |
| 263 | # Deliberately drop version information here, not wanted/supported by deb |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 264 | rprovides = dict.fromkeys(bb.utils.explode_dep_versions2(localdata.getVar("RPROVIDES") or ""), []) |
| 265 | # Remove file paths if any from rprovides, debian does not support custom providers |
| 266 | for key in list(rprovides.keys()): |
| 267 | if key.startswith('/'): |
| 268 | del rprovides[key] |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 269 | rprovides = collections.OrderedDict(sorted(rprovides.items(), key=lambda x: x[0])) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 270 | debian_cmp_remap(rprovides) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 271 | rreplaces = bb.utils.explode_dep_versions2(localdata.getVar("RREPLACES") or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 272 | debian_cmp_remap(rreplaces) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 273 | rconflicts = bb.utils.explode_dep_versions2(localdata.getVar("RCONFLICTS") or "") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 274 | debian_cmp_remap(rconflicts) |
| 275 | if rdepends: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 276 | ctrlfile.write("Depends: %s\n" % bb.utils.join_deps(rdepends)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 277 | if rsuggests: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 278 | ctrlfile.write("Suggests: %s\n" % bb.utils.join_deps(rsuggests)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 279 | if rrecommends: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 280 | ctrlfile.write("Recommends: %s\n" % bb.utils.join_deps(rrecommends)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 281 | if rprovides: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 282 | ctrlfile.write("Provides: %s\n" % bb.utils.join_deps(rprovides)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 283 | if rreplaces: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 284 | ctrlfile.write("Replaces: %s\n" % bb.utils.join_deps(rreplaces)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 285 | if rconflicts: |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 286 | ctrlfile.write("Conflicts: %s\n" % bb.utils.join_deps(rconflicts)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 287 | ctrlfile.close() |
| 288 | |
| 289 | for script in ["preinst", "postinst", "prerm", "postrm"]: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 290 | scriptvar = localdata.getVar('pkg_%s' % script) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 291 | if not scriptvar: |
| 292 | continue |
| 293 | scriptvar = scriptvar.strip() |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 294 | scriptfile = open(os.path.join(controldir, script), 'w') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 295 | |
| 296 | if scriptvar.startswith("#!"): |
| 297 | pos = scriptvar.find("\n") + 1 |
| 298 | scriptfile.write(scriptvar[:pos]) |
| 299 | else: |
| 300 | pos = 0 |
| 301 | scriptfile.write("#!/bin/sh\n") |
| 302 | |
| 303 | # Prevent the prerm/postrm scripts from being run during an upgrade |
| 304 | if script in ('prerm', 'postrm'): |
| 305 | scriptfile.write('[ "$1" != "upgrade" ] || exit 0\n') |
| 306 | |
| 307 | scriptfile.write(scriptvar[pos:]) |
| 308 | scriptfile.write('\n') |
| 309 | scriptfile.close() |
Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 310 | os.chmod(os.path.join(controldir, script), 0o755) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 311 | |
| 312 | conffiles_str = ' '.join(get_conffiles(pkg, d)) |
| 313 | if conffiles_str: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 314 | conffiles = open(os.path.join(controldir, 'conffiles'), 'w') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 315 | for f in conffiles_str.split(): |
| 316 | if os.path.exists(oe.path.join(root, f)): |
| 317 | conffiles.write('%s\n' % f) |
| 318 | conffiles.close() |
| 319 | |
| 320 | os.chdir(basedir) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 321 | subprocess.check_output("PATH=\"%s\" dpkg-deb -b %s %s" % (localdata.getVar("PATH"), root, pkgoutdir), |
| 322 | stderr=subprocess.STDOUT, |
| 323 | shell=True) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 324 | |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 325 | finally: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 326 | cleanupcontrol(root) |
| 327 | bb.utils.unlockfile(lf) |
Brad Bishop | d7bf8c1 | 2018-02-25 22:55:05 -0500 | [diff] [blame] | 328 | |
| 329 | # Otherwise allarch packages may change depending on override configuration |
| 330 | deb_write_pkg[vardepsexclude] = "OVERRIDES" |
| 331 | |
Patrick Williams | d8c66bc | 2016-06-20 12:57:21 -0500 | [diff] [blame] | 332 | # Indirect references to these vars |
| 333 | do_package_write_deb[vardeps] += "PKGV PKGR PKGV DESCRIPTION SECTION PRIORITY MAINTAINER DPKG_ARCH PN HOMEPAGE" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 334 | |
| 335 | SSTATETASKS += "do_package_write_deb" |
| 336 | do_package_write_deb[sstate-inputdirs] = "${PKGWRITEDIRDEB}" |
| 337 | do_package_write_deb[sstate-outputdirs] = "${DEPLOY_DIR_DEB}" |
| 338 | |
| 339 | python do_package_write_deb_setscene () { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 340 | tmpdir = d.getVar('TMPDIR') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 341 | |
| 342 | if os.access(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN"),os.R_OK): |
| 343 | os.unlink(os.path.join(tmpdir, "stamps", "DEB_PACKAGE_INDEX_CLEAN")) |
| 344 | |
| 345 | sstate_setscene(d) |
| 346 | } |
| 347 | addtask do_package_write_deb_setscene |
| 348 | |
| 349 | python () { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 350 | if d.getVar('PACKAGES') != '': |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 351 | deps = ' dpkg-native:do_populate_sysroot virtual/fakeroot-native:do_populate_sysroot' |
| 352 | d.appendVarFlag('do_package_write_deb', 'depends', deps) |
| 353 | d.setVarFlag('do_package_write_deb', 'fakeroot', "1") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | python do_package_write_deb () { |
| 357 | bb.build.exec_func("read_subpackage_metadata", d) |
| 358 | bb.build.exec_func("do_package_deb", d) |
| 359 | } |
| 360 | do_package_write_deb[dirs] = "${PKGWRITEDIRDEB}" |
| 361 | do_package_write_deb[cleandirs] = "${PKGWRITEDIRDEB}" |
| 362 | do_package_write_deb[umask] = "022" |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 363 | do_package_write_deb[depends] += "${@oe.utils.build_depends_string(d.getVar('PACKAGE_WRITE_DEPS'), 'do_populate_sysroot')}" |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 364 | addtask package_write_deb after do_packagedata do_package |
| 365 | |
| 366 | |
| 367 | PACKAGEINDEXDEPS += "dpkg-native:do_populate_sysroot" |
| 368 | PACKAGEINDEXDEPS += "apt-native:do_populate_sysroot" |
| 369 | |
| 370 | do_build[recrdeptask] += "do_package_write_deb" |