Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 1 | # Debian package renaming only occurs when a package is built |
| 2 | # We therefore have to make sure we build all runtime packages |
| 3 | # before building the current package to make the packages runtime |
| 4 | # depends are correct |
| 5 | # |
| 6 | # Custom library package names can be defined setting |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 7 | # DEBIANNAME: + pkgname to the desired name. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 8 | # |
| 9 | # Better expressed as ensure all RDEPENDS package before we package |
| 10 | # This means we can't have circular RDEPENDS/RRECOMMENDS |
| 11 | |
| 12 | AUTO_LIBNAME_PKGS = "${PACKAGES}" |
| 13 | |
| 14 | inherit package |
| 15 | |
| 16 | DEBIANRDEP = "do_packagedata" |
| 17 | do_package_write_ipk[rdeptask] = "${DEBIANRDEP}" |
| 18 | do_package_write_deb[rdeptask] = "${DEBIANRDEP}" |
| 19 | do_package_write_tar[rdeptask] = "${DEBIANRDEP}" |
| 20 | do_package_write_rpm[rdeptask] = "${DEBIANRDEP}" |
| 21 | |
| 22 | python () { |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 23 | if not d.getVar("PACKAGES"): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 24 | d.setVar("DEBIANRDEP", "") |
| 25 | } |
| 26 | |
| 27 | python debian_package_name_hook () { |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 28 | import glob, copy, stat, errno, re, pathlib, subprocess |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 29 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 30 | pkgdest = d.getVar("PKGDEST") |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 31 | packages = d.getVar('PACKAGES') |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 32 | so_re = re.compile(r"lib.*\.so") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 33 | |
| 34 | def socrunch(s): |
| 35 | s = s.lower().replace('_', '-') |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 36 | m = re.match(r"^(.*)(.)\.so\.(.*)$", s) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 37 | if m is None: |
| 38 | return None |
| 39 | if m.group(2) in '0123456789': |
| 40 | bin = '%s%s-%s' % (m.group(1), m.group(2), m.group(3)) |
| 41 | else: |
| 42 | bin = m.group(1) + m.group(2) + m.group(3) |
| 43 | dev = m.group(1) + m.group(2) |
| 44 | return (bin, dev) |
| 45 | |
| 46 | def isexec(path): |
| 47 | try: |
| 48 | s = os.stat(path) |
| 49 | except (os.error, AttributeError): |
| 50 | return 0 |
| 51 | return (s[stat.ST_MODE] & stat.S_IEXEC) |
| 52 | |
| 53 | def add_rprovides(pkg, d): |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 54 | newpkg = d.getVar('PKG:' + pkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 55 | if newpkg and newpkg != pkg: |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 56 | provs = (d.getVar('RPROVIDES:' + pkg) or "").split() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 57 | if pkg not in provs: |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 58 | d.appendVar('RPROVIDES:' + pkg, " " + pkg + " (=" + d.getVar("PKGV") + ")") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 59 | |
| 60 | def auto_libname(packages, orig_pkg): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 61 | p = lambda var: pathlib.PurePath(d.getVar(var)) |
| 62 | libdirs = (p("base_libdir"), p("libdir")) |
| 63 | bindirs = (p("base_bindir"), p("base_sbindir"), p("bindir"), p("sbindir")) |
| 64 | |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 65 | sonames = [] |
| 66 | has_bins = 0 |
| 67 | has_libs = 0 |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 68 | for f in pkgfiles[orig_pkg]: |
| 69 | # This is .../packages-split/orig_pkg/ |
| 70 | pkgpath = pathlib.PurePath(pkgdest, orig_pkg) |
| 71 | # Strip pkgpath off the full path to a file in the package, re-root |
| 72 | # so it is absolute, and then get the parent directory of the file. |
| 73 | path = pathlib.PurePath("/") / (pathlib.PurePath(f).relative_to(pkgpath).parent) |
| 74 | if path in bindirs: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 75 | has_bins = 1 |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 76 | if path in libdirs: |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 77 | has_libs = 1 |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 78 | if so_re.match(os.path.basename(f)): |
| 79 | try: |
| 80 | cmd = [d.expand("${TARGET_PREFIX}objdump"), "-p", f] |
| 81 | output = subprocess.check_output(cmd).decode("utf-8") |
Brad Bishop | 1932369 | 2019-04-05 15:28:33 -0400 | [diff] [blame] | 82 | for m in re.finditer(r"\s+SONAME\s+([^\s]+)", output): |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 83 | if m.group(1) not in sonames: |
| 84 | sonames.append(m.group(1)) |
| 85 | except subprocess.CalledProcessError: |
| 86 | pass |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 87 | bb.debug(1, 'LIBNAMES: pkg %s libs %d bins %d sonames %s' % (orig_pkg, has_libs, has_bins, sonames)) |
| 88 | soname = None |
| 89 | if len(sonames) == 1: |
| 90 | soname = sonames[0] |
| 91 | elif len(sonames) > 1: |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 92 | lead = d.getVar('LEAD_SONAME') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 93 | if lead: |
| 94 | r = re.compile(lead) |
| 95 | filtered = [] |
| 96 | for s in sonames: |
| 97 | if r.match(s): |
| 98 | filtered.append(s) |
| 99 | if len(filtered) == 1: |
| 100 | soname = filtered[0] |
| 101 | elif len(filtered) > 1: |
| 102 | bb.note("Multiple matches (%s) for LEAD_SONAME '%s'" % (", ".join(filtered), lead)) |
| 103 | else: |
| 104 | bb.note("Multiple libraries (%s) found, but LEAD_SONAME '%s' doesn't match any of them" % (", ".join(sonames), lead)) |
| 105 | else: |
| 106 | bb.note("Multiple libraries (%s) found and LEAD_SONAME not defined" % ", ".join(sonames)) |
| 107 | |
| 108 | if has_libs and not has_bins and soname: |
| 109 | soname_result = socrunch(soname) |
| 110 | if soname_result: |
| 111 | (pkgname, devname) = soname_result |
| 112 | for pkg in packages.split(): |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 113 | if (d.getVar('PKG:' + pkg, False) or d.getVar('DEBIAN_NOAUTONAME:' + pkg, False)): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 114 | add_rprovides(pkg, d) |
| 115 | continue |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 116 | debian_pn = d.getVar('DEBIANNAME:' + pkg, False) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 117 | if debian_pn: |
| 118 | newpkg = debian_pn |
| 119 | elif pkg == orig_pkg: |
| 120 | newpkg = pkgname |
| 121 | else: |
| 122 | newpkg = pkg.replace(orig_pkg, devname, 1) |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 123 | mlpre=d.getVar('MLPREFIX') |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 124 | if mlpre: |
| 125 | if not newpkg.find(mlpre) == 0: |
| 126 | newpkg = mlpre + newpkg |
| 127 | if newpkg != pkg: |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame] | 128 | bb.note("debian: renaming %s to %s" % (pkg, newpkg)) |
Patrick Williams | 213cb26 | 2021-08-07 19:21:33 -0500 | [diff] [blame] | 129 | d.setVar('PKG:' + pkg, newpkg) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 130 | add_rprovides(pkg, d) |
| 131 | else: |
| 132 | add_rprovides(orig_pkg, d) |
| 133 | |
| 134 | # reversed sort is needed when some package is substring of another |
| 135 | # ie in ncurses we get without reverse sort: |
| 136 | # DEBUG: LIBNAMES: pkgname libtic5 devname libtic pkg ncurses-libtic orig_pkg ncurses-libtic debian_pn None newpkg libtic5 |
| 137 | # and later |
| 138 | # DEBUG: LIBNAMES: pkgname libtic5 devname libtic pkg ncurses-libticw orig_pkg ncurses-libtic debian_pn None newpkg libticw |
| 139 | # so we need to handle ncurses-libticw->libticw5 before ncurses-libtic->libtic5 |
Brad Bishop | 6e60e8b | 2018-02-01 10:27:11 -0500 | [diff] [blame] | 140 | for pkg in sorted((d.getVar('AUTO_LIBNAME_PKGS') or "").split(), reverse=True): |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 141 | auto_libname(packages, pkg) |
| 142 | } |
| 143 | |
| 144 | EXPORT_FUNCTIONS package_name_hook |
| 145 | |
| 146 | DEBIAN_NAMES = "1" |