"pkgrel_bump --auto": Handle subpackages properly (#1388)

`pmbootstrap pkgrel_bump --auto` automatically increases the pkgrel for
packages linking against libraries, which don't exist anymore (because
the soname has been changed). The feature is explained in detail in

The previous implementation did not detect soname breakage, when a
subpackage linked against a certain library, but the main package
did not (e.g. `qt5-qtbase-mysql` and `qt5-qtbase`). This was, because
we iterated over the aports/* to find the packages to be checked.

To fix this, we are iterating over the packages found in the APKINDEX
files instead (of both the locally compiled packages and the downloaded
index from the pmOS mirror).

Details:
* `pmb/helpers/pkgrel_bump.py`:
  * Rewrite `auto_apkindex_package()` to act upon a given parsed
    `aport` and `apk` (from the index) instead of finding the `apk`
    dict by itself (we need it earlier anyway).
  * Rewrite `auto()` to iterate over APKINDEX files instead of aports
    * Skip packages already found, so the `pkgrel` does not get
      increased multiple times when the same package was found in
      multipe index files.
* Put the package name at the beginning of the log messages to make
  them more readable
* testdata: Create a new `testsubpkg` aport, where only the subpackage
  links against `testlib`
* Adjust testing code to test everything with `testsubpkg` as well.

NOTE: This makes the command a bit slower, but we could improve
performance again by smart caching of `pmb.parse.apkindex.depends()`.
This could come in a future PR, the important part here is that the
command is bug-free again with this fix.
This commit is contained in:
Oliver Smith 2018-04-15 21:34:40 +00:00 committed by GitHub
parent 4388c6614d
commit ca20ead505
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 101 additions and 56 deletions

View File

@ -16,7 +16,6 @@ GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with pmbootstrap. If not, see <http://www.gnu.org/licenses/>.
"""
import glob
import logging
import os
@ -66,7 +65,7 @@ def auto_apkindex_files(args):
Get the paths to the APKINDEX files, that need to be analyzed, sorted by
arch. Relevant are the local pmbootstrap generated APKINDEX as well as the
APKINDEX from the pmOS binary repo.
.
:returns: {"armhf": "...../APKINDEX.tar.gz", ...}
"""
pmb.helpers.repo.update(args)
@ -84,46 +83,44 @@ def auto_apkindex_files(args):
return ret
def auto_apkindex_package(args, pkgname, aport_version, apkindex, arch,
dry=False):
def auto_apkindex_package(args, arch, aport, apk, dry=False):
"""
Bump the pkgrel of a specific package if it is outdated in the given
APKINDEX.
:param pkgname: name of the package
:param aport_version: combination of pkgver and pkgrel (e.g. "1.23-r1")
:param apkindex: path to the APKINDEX.tar.gz file
:param arch: the architecture, e.g. "armhf"
:param aport: parsed APKBUILD of the binary package's origin:
{"pkgname": ..., "pkgver": ..., "pkgrel": ..., ...}
:param apk: information about the binary package from the APKINDEX:
{"version": ..., "depends": [...], ...}
:param dry: don't modify the APKBUILD, just print the message
:returns: True when there was an APKBUILD that needed to be changed.
"""
# Binary package
binary = pmb.parse.apkindex.package(args, pkgname, must_exist=False,
indexes=[apkindex])
if not binary:
return
version_aport = aport["pkgver"] + "-r" + aport["pkgrel"]
version_apk = apk["version"]
pkgname = aport["pkgname"]
# Skip when aport version != binary package version
compare = pmb.parse.version.compare(aport_version,
binary["version"])
compare = pmb.parse.version.compare(version_aport, version_apk)
if compare == -1:
logging.warning("WARNING: Skipping '" + pkgname +
"' in index " + apkindex + ", because the"
" binary version " + binary["version"] +
" is higher than the aport version " +
aport_version)
logging.warning("{}: skipping, because the aport version {} is lower"
" than the binary version {}".format(pkgname,
version_aport,
version_apk))
return
if compare == 1:
logging.verbose(pkgname + ": aport version bigger than the"
" one in the APKINDEX, skipping:" +
apkindex)
logging.verbose("{}: skipping, because the aport version {} is higher"
" than the binary version {}".format(pkgname,
version_aport,
version_apk))
return
# Find missing depends
logging.verbose(pkgname + ": checking depends: " +
",".join(binary["depends"]))
depends = apk["depends"]
logging.verbose("{}: checking depends: {}".format(pkgname,
", ".join(depends)))
missing = []
for depend in binary["depends"]:
for depend in depends:
providers = pmb.parse.apkindex.providers(args, depend, arch,
must_exist=False)
if providers == {}:
@ -143,21 +140,26 @@ def auto_apkindex_package(args, pkgname, aport_version, apkindex, arch,
def auto(args, dry=False):
"""
:returns: True when there was an APKBUILD that needed to be changed.
:returns: list of aport names, where the pkgrel needed to be changed
"""
# Get APKINDEX files
arch_apkindexes = auto_apkindex_files(args)
# Iterate over aports
ret = False
for aport in glob.glob(args.aports + "/*/*"):
pkgname = os.path.basename(aport)
aport = pmb.parse.apkbuild(args, aport + "/APKBUILD")
aport_version = aport["pkgver"] + "-r" + aport["pkgrel"]
for arch, apkindexes in arch_apkindexes.items():
for apkindex in apkindexes:
if auto_apkindex_package(args, pkgname, aport_version, apkindex,
arch, dry):
ret = True
ret = []
for arch, paths in auto_apkindex_files(args).items():
for path in paths:
logging.info("scan " + path)
index = pmb.parse.apkindex.parse(args, path, False)
for pkgname, apk in index.items():
origin = apk["origin"]
# Only increase once!
if origin in ret:
logging.verbose("{}: origin '{}' found again".format(pkgname,
origin))
continue
aport_path = pmb.build.other.find_aport(args, origin, False)
if not aport_path:
logging.warning("{}: origin '{}' aport not found".format(
pkgname, origin))
continue
aport = pmb.parse.apkbuild(args, aport_path + "/APKBUILD")
if auto_apkindex_package(args, arch, aport, apk, dry):
ret.append(pkgname)
return ret

View File

@ -98,7 +98,7 @@ def setup_work(args, tmpdir):
"/_aports/" + folder])
pmb.helpers.run.user(args, ["cp", "-r", args.aports + "/device/device-" +
args.device, tmpdir + "/_aports/device"])
for pkgname in ["testlib", "testapp"]:
for pkgname in ["testlib", "testapp", "testsubpkg"]:
pmb.helpers.run.user(args, ["cp", "-r",
"test/testdata/pkgrel_bump/aports/" + pkgname,
tmpdir + "/_aports/main/" + pkgname])
@ -112,12 +112,16 @@ def setup_work(args, tmpdir):
"/_pmbootstrap.cfg"])
def verify_pkgrels(args, tmpdir, pkgrel_testlib, pkgrel_testapp):
def verify_pkgrels(args, tmpdir, pkgrel_testlib, pkgrel_testapp,
pkgrel_testsubpkg):
"""
Verify the pkgrels of the two test APKBUILDs "testlib" and "testapp".
Verify the pkgrels of the three test APKBUILDs ("testlib", "testapp",
"testsubpkg").
"""
args.cache["apkbuild"] = {}
mapping = {"testlib": pkgrel_testlib, "testapp": pkgrel_testapp}
mapping = {"testlib": pkgrel_testlib,
"testapp": pkgrel_testapp,
"testsubpkg": pkgrel_testsubpkg}
for pkgname, pkgrel in mapping.items():
# APKBUILD path
path = tmpdir + "/_aports/main/" + pkgname + "/APKBUILD"
@ -133,38 +137,37 @@ def test_pkgrel_bump_high_level(args, tmpdir):
setup_work(args, tmpdir)
# Let pkgrel_bump exit normally
pmbootstrap(args, tmpdir, ["build", "testlib"])
pmbootstrap(args, tmpdir, ["build", "testapp"])
pmbootstrap(args, tmpdir, ["build", "testlib", "testapp", "testsubpkg"])
pmbootstrap(args, tmpdir, ["pkgrel_bump", "--dry", "--auto"])
verify_pkgrels(args, tmpdir, 0, 0)
verify_pkgrels(args, tmpdir, 0, 0, 0)
# Increase soname (testlib soname changes with the pkgrel)
pmbootstrap(args, tmpdir, ["pkgrel_bump", "testlib"])
verify_pkgrels(args, tmpdir, 1, 0)
verify_pkgrels(args, tmpdir, 1, 0, 0)
pmbootstrap(args, tmpdir, ["build", "testlib"])
pmbootstrap(args, tmpdir, ["pkgrel_bump", "--dry", "--auto"])
verify_pkgrels(args, tmpdir, 1, 0)
verify_pkgrels(args, tmpdir, 1, 0, 0)
# Delete package with previous soname (--auto-dry exits with >0 now)
pmb.helpers.run.root(args, ["rm", tmpdir + "/packages/" +
args.arch_native + "/testlib-1.0-r0.apk"])
pmbootstrap(args, tmpdir, ["index"])
pmbootstrap(args, tmpdir, ["pkgrel_bump", "--dry", "--auto"], False)
verify_pkgrels(args, tmpdir, 1, 0)
verify_pkgrels(args, tmpdir, 1, 0, 0)
# Bump the pkgrel of testapp and build it
# Bump pkgrel and build testapp/testsubpkg
pmbootstrap(args, tmpdir, ["pkgrel_bump", "--auto"])
verify_pkgrels(args, tmpdir, 1, 1)
pmbootstrap(args, tmpdir, ["build", "testapp"])
verify_pkgrels(args, tmpdir, 1, 1, 1)
pmbootstrap(args, tmpdir, ["build", "testapp", "testsubpkg"])
# After rebuilding, pkgrel_bump --auto-dry exits with 0
pmbootstrap(args, tmpdir, ["pkgrel_bump", "--dry", "--auto"])
verify_pkgrels(args, tmpdir, 1, 1)
verify_pkgrels(args, tmpdir, 1, 1, 1)
# Test running with specific package names
pmbootstrap(args, tmpdir, ["pkgrel_bump", "invalid_package_name"], False)
pmbootstrap(args, tmpdir, ["pkgrel_bump", "--dry", "testlib"], False)
verify_pkgrels(args, tmpdir, 1, 1)
verify_pkgrels(args, tmpdir, 1, 1, 1)
# Clean up
pmbootstrap(args, tmpdir, ["shutdown"])

View File

@ -0,0 +1,33 @@
pkgname=testsubpkg
pkgver=1.0
pkgrel=0
pkgdesc="subpackage using the testlib (for testing soname bumps)"
url="https://postmarketos.org"
arch="all"
license="MIT"
depends=""
makedepends="testlib"
subpackages="$pkgname-app"
source="testapp.c"
options=""
build() {
cd "$srcdir"
$CC testapp.c -o testapp -L/usr/lib/ -ltestlib
}
check() {
cd "$srcdir"
printf 'hello, world from testlib!\n' > expected
./testapp > real
diff -q expected real
}
package() {
mkdir -p "$pkgdir"
}
app() {
install -Dm755 "$srcdir/testapp" "$subpkgdir/usr/bin/testapp"
}
sha512sums="73b167575dc0082a1277b0430f095509885c7aaf55e59bad148825a9879f91fe41c6479bb7f34c0cdd15284b0aadd904a5ba2c1ea85fb8bfb061e1cbf4322d76 testapp.c"

View File

@ -0,0 +1,7 @@
#include <stdio.h>
#include <testlib.h>
int main(int argc, char **argv) {
testlib_hello();
return 0;
}