From 2106e13f97fa81b1a80996f270bd52ca77e108bb Mon Sep 17 00:00:00 2001
From: Caleb Connolly <caleb@postmarketos.org>
Date: Sat, 26 Oct 2024 15:25:26 +0200
Subject: [PATCH] build: package: allow building old versions of packages with
 --force (MR 2457)

It may be desirable to test older versions of packages, allow them to be
built when --force is specified and print a warning that they won't be
installed automatically.

Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
---
 pmb/build/_package.py | 23 ++++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/pmb/build/_package.py b/pmb/build/_package.py
index 895c22da5..821763af8 100644
--- a/pmb/build/_package.py
+++ b/pmb/build/_package.py
@@ -480,18 +480,27 @@ def packages(
         channel = pmb.config.pmaports.read_config(aports)["channel"]
         index_data = pmb.parse.apkindex.package(name, arch, False)
         # Make sure we aren't building a package that will never be used! This can happen if
-        # building with --src with an outdated pmaports checkout.
+        # building with --src with an outdated pmaports checkout. Unless --force is used
+        # in which case we assume it was intentional.
         if (
             index_data
             and pmb.parse.version.compare(index_data.version, f"{pkgver}-r{apkbuild['pkgrel']}")
             == 1
         ):
-            raise NonBugError(
-                f"A binary package for {name} has a newer version ({index_data.version})"
-                f" than the source ({pkgver}-{apkbuild['pkgrel']}). Please ensure your pmaports branch is up"
-                " to date and that you don't have a newer version of the package in your local"
-                f" binary repo ({context.config.work / 'packages' / channel / pkg_arch})."
-            )
+            if force:
+                logging.warning(
+                    f"WARNING: A binary package for {name} has a newer version ({index_data.version})"
+                    f" than the source ({pkgver}-{apkbuild['pkgrel']}). The package to be build will"
+                    f" not be installed automatically, use 'apk add {name}={pkgver}-r{apkbuild['pkgrel']}'"
+                    " to install it."
+                )
+            else:
+                raise NonBugError(
+                    f"A binary package for {name} has a newer version ({index_data.version})"
+                    f" than the source ({pkgver}-{apkbuild['pkgrel']}). Please ensure your pmaports branch is up"
+                    " to date and that you don't have a newer version of the package in your local"
+                    f" binary repo ({context.config.work / 'packages' / channel / pkg_arch})."
+                )
         build_queue.append(
             {
                 "name": name,
-- 
GitLab