pmbootstrap-meow/pmb/aportgen/grub_efi.py
Newbyte d02d6f4bc9
pmb.aportgen: Update APKINDEX for relevant arch before parsing it (MR 2509)
This might have saved me a couple of minutes of debugging, at least.
While working with the aportgen code I had two distinct issues:

 1. APKINDEX was outdated, so I got an error about not being able to
    download the supposedly latest version of BusyBox as it no longer
    existed on Alpine's mirror.
 2. APKINDEX had not been created by any other command, so aportgen
    would tell me that it couldn't find the "busybox" package.

The changes in this commit resolves both of these issues from my
testing.
2024-12-19 16:29:32 +01:00

62 lines
2.2 KiB
Python

# Copyright 2023 Nick Reitemeyer, Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later
import pmb.aportgen.core
import pmb.build
import pmb.chroot.apk
from pmb.core.arch import Arch
import pmb.helpers.repo
import pmb.helpers.run
import pmb.parse.apkindex
from pmb.core import Chroot
def generate(pkgname: str) -> None:
arch = Arch.x86
if pkgname != "grub-efi-x86":
raise RuntimeError("only grub-efi-x86 is available")
# Update or create APKINDEX for relevant arch so we know it exists and is recent.
pmb.helpers.repo.update(arch)
package_data = pmb.parse.apkindex.package("grub", arch=arch)
if package_data is None:
raise RuntimeError("Couldn't find package grub!")
version = package_data.version
pkgver = version.split("-r")[0]
pkgrel = version.split("-r")[1]
tempdir = pmb.aportgen.core.prepare_tempdir()
# Write the APKBUILD
channel_cfg = pmb.config.pmaports.read_config_channel()
mirrordir = channel_cfg["mirrordir_alpine"]
apkbuild_path = Chroot.native() / tempdir / "APKBUILD"
apk_name = f'"$srcdir/grub-efi-$pkgver-r$pkgrel-$_arch-{mirrordir}.apk"'
with open(apkbuild_path, "w", encoding="utf-8") as handle:
apkbuild = f"""\
# Automatically generated aport, do not edit!
# Generator: pmbootstrap aportgen {pkgname}
pkgname={pkgname}
pkgver={pkgver}
pkgrel={pkgrel}
_arch="{arch}"
_mirror="{pmb.config.aportgen_mirror_alpine}"
pkgdesc="GRUB $_arch EFI files for every architecture"
url="https://www.gnu.org/software/grub/"
license="GPL-3.0-or-later"
arch="{Arch.native()}"
source="grub-efi-$pkgver-r$pkgrel-$_arch-{mirrordir}.apk::$_mirror/{mirrordir}/main/$_arch/grub-efi-$pkgver-r$pkgrel.apk"
package() {{
mkdir -p "$pkgdir"
cd "$pkgdir"
tar -xf {apk_name}
rm .PKGINFO .SIGN.*
}}
"""
for line in apkbuild.split("\n"):
handle.write(line[12:].replace(" " * 4, "\t") + "\n")
pmb.aportgen.core.generate_checksums(tempdir, apkbuild_path)