From bfbb09589535d8760e8d26ae4340fe7a948fbd2e Mon Sep 17 00:00:00 2001 From: Oliver Smith Date: Sun, 21 Jun 2020 12:14:07 +0200 Subject: [PATCH] pmb/aportgen/musl.py: fix distfile collisions (MR 1947) Add the Alpine mirrordir (e.g. "edge", "v3.12") to the distfile, so musl-*.apk files of the same version and arch but from different mirrordirs do not collide. Let "abuild checksum" download these apks and generate the checksums, instead of letting apk download them as side-effect of initializing foreign arch chroots. The latter did not work anymore, because we would copy the apk file with a glob that may matches the hash of either mirrordir. Essentially: glob.glob(f"{args.work}/cache_apk_{arch}/{subpkgname}-{version}.*.apk")[0] In the context of the on-device installer, I found that calculating this hash is not trivial, so let's just avoid it here as well. While at it, order the imports of musl.py alphabetically. --- pmb/aportgen/musl.py | 58 +++++++++++++++----------------------------- 1 file changed, 20 insertions(+), 38 deletions(-) diff --git a/pmb/aportgen/musl.py b/pmb/aportgen/musl.py index 9dbe8dbf..296ce9db 100644 --- a/pmb/aportgen/musl.py +++ b/pmb/aportgen/musl.py @@ -1,19 +1,14 @@ # Copyright 2020 Oliver Smith # SPDX-License-Identifier: GPL-3.0-or-later -import glob -import os -import pmb.helpers.run import pmb.aportgen.core -import pmb.parse.apkindex +import pmb.build import pmb.chroot.apk import pmb.chroot.apk_static +import pmb.helpers.run +import pmb.parse.apkindex def generate(args, pkgname): - # Install musl in chroot to get verified apks - arch = pkgname.split("-")[1] - pmb.chroot.apk.install(args, ["musl-dev"], "buildroot_" + arch) - # Parse musl version from APKINDEX package_data = pmb.parse.apkindex.package(args, "musl") version = package_data["version"] @@ -21,37 +16,21 @@ def generate(args, pkgname): pkgrel = version.split("-r")[1] # Architectures to build this package for + arch = pkgname.split("-")[1] arches = list(pmb.config.build_device_architectures) arches.remove(arch) - # Copy the apk files to the distfiles cache - for subpkgname in ["musl", "musl-dev"]: - pattern = (args.work + "/cache_apk_" + arch + "/" + subpkgname + - "-" + version + ".*.apk") - glob_result = glob.glob(pattern) - if not len(glob_result): - raise RuntimeError("Could not find aport " + pattern + "!" - " Update your aports_upstream git repo" - " to the latest version, delete your http cache" - " (pmbootstrap zap -hc) and try again.") - path = glob_result[0] - path_target = (args.work + "/cache_distfiles/" + subpkgname + "-" + - version + "-" + arch + ".apk") - if not os.path.exists(path_target): - pmb.helpers.run.root(args, ["cp", path, path_target]) - - # Hash the distfiles - hashes = pmb.chroot.user(args, ["sha512sum", - "musl-" + version + "-" + arch + ".apk", - "musl-dev-" + version + "-" + arch + ".apk"], "buildroot_" + arch, - "/var/cache/distfiles", output_return=True) + # Prepare aportgen tempdir inside and outside of chroot + tempdir = "/tmp/aportgen" + pmb.chroot.root(args, ["rm", "-rf", tempdir]) + pmb.helpers.run.user(args, ["mkdir", "-p", f"{args.work}/aportgen", + f"{args.work}/chroot_native/{tempdir}"]) # Write the APKBUILD channel_cfg = pmb.config.pmaports.read_config_channel(args) mirrordir = channel_cfg["mirrordir_alpine"] - pmb.helpers.run.user(args, ["mkdir", "-p", args.work + "/aportgen"]) - with open(args.work + "/aportgen/APKBUILD", "w", encoding="utf-8") as handle: - # Variables + apkbuild_path = f"{args.work}/chroot_native/{tempdir}/APKBUILD" + with open(apkbuild_path, "w", encoding="utf-8") as handle: apkbuild = f"""\ # Automatically generated aport, do not edit! # Generator: pmbootstrap aportgen {pkgname} @@ -78,8 +57,8 @@ def generate(args, pkgname): _target="$(arch_to_hostspec $_arch)" source=" - musl-$pkgver-r$pkgrel-$_arch.apk::$_mirror/{mirrordir}/main/$_arch/musl-$pkgver-r$pkgrel.apk - musl-dev-$pkgver-r$pkgrel-$_arch.apk::$_mirror/{mirrordir}/main/$_arch/musl-dev-$pkgver-r$pkgrel.apk + musl-$pkgver-r$pkgrel-$_arch-{mirrordir}.apk::$_mirror/{mirrordir}/main/$_arch/musl-$pkgver-r$pkgrel.apk + musl-dev-$pkgver-r$pkgrel-$_arch-{mirrordir}.apk::$_mirror/{mirrordir}/main/$_arch/musl-dev-$pkgver-r$pkgrel.apk " package() {{ @@ -87,7 +66,7 @@ def generate(args, pkgname): cd "$pkgdir/usr/$_target" # Use 'busybox tar' to avoid 'tar: Child returned status 141' # on some machines (builds.sr.ht, gitlab-ci). See pmaports#26. - busybox tar -xf $srcdir/musl-$pkgver-r$pkgrel-$_arch.apk + busybox tar -xf $srcdir/musl-$pkgver-r$pkgrel-$_arch-{mirrordir}.apk rm .PKGINFO .SIGN.* }} package_dev() {{ @@ -95,7 +74,7 @@ def generate(args, pkgname): cd "$subpkgdir/usr/$_target" # Use 'busybox tar' to avoid 'tar: Child returned status 141' # on some machines (builds.sr.ht, gitlab-ci). See pmaports#26. - busybox tar -xf $srcdir/musl-dev-$pkgver-r$pkgrel-$_arch.apk + busybox tar -xf $srcdir/musl-dev-$pkgver-r$pkgrel-$_arch-{mirrordir}.apk rm .PKGINFO .SIGN.* # symlink everything from /usr/$_target/usr/* to /usr/$_target/* @@ -113,5 +92,8 @@ def generate(args, pkgname): for line in apkbuild.split("\n"): handle.write(line[12:].replace(" " * 4, "\t") + "\n") - # Hashes - handle.write("sha512sums=\"" + hashes.rstrip() + "\"\n") + # Generate checksums + pmb.build.init(args) + pmb.chroot.root(args, ["chown", "-R", "pmos:pmos", tempdir]) + pmb.chroot.user(args, ["abuild", "checksum"], working_dir=tempdir) + pmb.helpers.run.user(args, ["cp", apkbuild_path, f"{args.work}/aportgen"])