pmb.commands: Add pkgver_bump (MR 2415)

Similar to pkgrel but for pkgver. Useful when dealing with e.g.
metapackages.

[ci:skip-build]: already built successfully in CI
This commit is contained in:
Stefan Hansson 2024-09-28 23:25:51 +02:00
parent a1fdd01173
commit 742300b090
No known key found for this signature in database
GPG key ID: 8A700086A9FE41FD
4 changed files with 61 additions and 12 deletions

View file

@ -16,6 +16,7 @@ from .repo_bootstrap import RepoBootstrap
from .shutdown import Shutdown from .shutdown import Shutdown
from .test import Test from .test import Test
from .pkgrel_bump import PkgrelBump from .pkgrel_bump import PkgrelBump
from .pkgver_bump import PkgverBump
from .pull import Pull from .pull import Pull
from .kconfig_check import KConfigCheck from .kconfig_check import KConfigCheck
from .kconfig_edit import KConfigEdit from .kconfig_edit import KConfigEdit
@ -76,6 +77,8 @@ def run_command(args: PmbArgs):
command = Test(args.action_test) command = Test(args.action_test)
case "pkgrel_bump": case "pkgrel_bump":
command = PkgrelBump(args.packages, args.dry, args.auto) command = PkgrelBump(args.packages, args.dry, args.auto)
case "pkgver_bump":
command = PkgverBump(args.packages)
case "pull": case "pull":
command = Pull() command = Pull()
case "kconfig": case "kconfig":

View file

@ -0,0 +1,20 @@
# Copyright 2024 Stefan Hansson
# SPDX-License-Identifier: GPL-3.0-or-later
from pmb import commands
import pmb.helpers.pkgrel_bump
class PkgverBump(commands.Command):
def __init__(self, packages: list[str]) -> None:
self.packages = packages
def run(self) -> None:
# Each package must exist
for package in self.packages:
pmb.helpers.pmaports.find(package)
for package in self.packages:
pmb.helpers.pkgrel_bump.package(
package, bump_type=pmb.helpers.pkgrel_bump.BumpType.PKGVER
)

View file

@ -1,5 +1,7 @@
# Copyright 2023 Oliver Smith # Copyright 2023 Oliver Smith
# SPDX-License-Identifier: GPL-3.0-or-later # SPDX-License-Identifier: GPL-3.0-or-later
from enum import Enum
from pmb.core.arch import Arch from pmb.core.arch import Arch
from pmb.helpers import logging from pmb.helpers import logging
@ -10,27 +12,35 @@ import pmb.parse
import pmb.parse.apkindex import pmb.parse.apkindex
def package(pkgname: str, reason="", dry: bool = False) -> None: class BumpType(Enum):
"""Increase the pkgrel in the APKBUILD of a specific package. PKGREL = "pkgrel"
PKGVER = "pkgver"
def package(
pkgname: str, reason="", dry: bool = False, bump_type: BumpType = BumpType.PKGREL
) -> None:
"""Increase the pkgrel or pkgver in the APKBUILD of a specific package.
:param pkgname: name of the package :param pkgname: name of the package
:param reason: string to display as reason why it was increased :param reason: string to display as reason why it was increased
:param dry: don't modify the APKBUILD, just print the message :param dry: don't modify the APKBUILD, just print the message
:param bump_type: whether to bump pkgrel or pkgver
""" """
# Current and new pkgrel # Current and new pkgrel or pkgver
path = pmb.helpers.pmaports.find(pkgname) / "APKBUILD" path = pmb.helpers.pmaports.find(pkgname) / "APKBUILD"
apkbuild = pmb.parse.apkbuild(path) apkbuild = pmb.parse.apkbuild(path)
pkgrel = int(apkbuild["pkgrel"]) version = int(apkbuild[bump_type.value])
pkgrel_new = pkgrel + 1 version_new = version + 1
# Display the message, bail out in dry mode # Display the message, bail out in dry mode
logging.info( logging.info(
"Increase '" "Increase '"
+ pkgname + pkgname
+ "' pkgrel (" + f"' {bump_type.value} ("
+ str(pkgrel) + str(version)
+ " -> " + " -> "
+ str(pkgrel_new) + str(version_new)
+ ")" + ")"
+ reason + reason
) )
@ -38,16 +48,21 @@ def package(pkgname: str, reason="", dry: bool = False) -> None:
return return
# Increase # Increase
old = "\npkgrel=" + str(pkgrel) + "\n" old = f"\n{bump_type.value}=" + str(version) + "\n"
new = "\npkgrel=" + str(pkgrel_new) + "\n" new = f"\n{bump_type.value}=" + str(version_new) + "\n"
pmb.helpers.file.replace(path, old, new) pmb.helpers.file.replace(path, old, new)
if bump_type == BumpType.PKGVER:
pkgrel = int(apkbuild["pkgrel"])
# Set pkgrel to 0 if we bump pkgver
pmb.helpers.file.replace(path, f"pkgrel={pkgrel}", "pkgrel=0")
# Verify # Verify
pmb.parse.apkbuild.cache_clear() pmb.parse.apkbuild.cache_clear()
apkbuild = pmb.parse.apkbuild(path) apkbuild = pmb.parse.apkbuild(path)
if int(apkbuild["pkgrel"]) != pkgrel_new: if int(apkbuild[bump_type.value]) != version_new:
raise RuntimeError( raise RuntimeError(
f"Failed to bump pkgrel for package '{pkgname}'." f"Failed to bump {bump_type.value} for package '{pkgname}'."
" Make sure that there's a line with exactly the" " Make sure that there's a line with exactly the"
f" string '{old.strip()}' and nothing else in: {path}" f" string '{old.strip()}' and nothing else in: {path}"
) )

View file

@ -577,6 +577,16 @@ def arguments_pkgrel_bump(subparser):
return ret return ret
def arguments_pkgver_bump(subparser):
ret = subparser.add_parser(
"pkgver_bump",
help="increase the pkgver and reset pkgrel to 0." " useful when dealing with metapackages.",
)
add_packages_arg(ret, nargs="*", default=[])
return ret
def arguments_aportupgrade(subparser): def arguments_aportupgrade(subparser):
ret = subparser.add_parser( ret = subparser.add_parser(
"aportupgrade", help="check for outdated" " packages that need upgrading" "aportupgrade", help="check for outdated" " packages that need upgrading"
@ -958,6 +968,7 @@ def get_parser():
arguments_initfs(sub) arguments_initfs(sub)
arguments_qemu(sub) arguments_qemu(sub)
arguments_pkgrel_bump(sub) arguments_pkgrel_bump(sub)
arguments_pkgver_bump(sub)
arguments_aportupgrade(sub) arguments_aportupgrade(sub)
arguments_newapkbuild(sub) arguments_newapkbuild(sub)
arguments_lint(sub) arguments_lint(sub)