aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--bpkg/pkg-build.cxx18
-rw-r--r--tests/pkg-build.testscript50
-rw-r--r--tests/pkg-system.testscript4
3 files changed, 63 insertions, 9 deletions
diff --git a/bpkg/pkg-build.cxx b/bpkg/pkg-build.cxx
index e15a9c9..c70aa9e 100644
--- a/bpkg/pkg-build.cxx
+++ b/bpkg/pkg-build.cxx
@@ -624,12 +624,20 @@ namespace bpkg
{
using constraint_type = build_package::constraint_type;
- // If the versions differ, we have to pick one. Start with the
- // newest version since if both satisfy, then that's the one we
- // should prefer. So get the first to try into p1 and the second
- // to try -- into p2.
+ // If the versions differ, we have to pick one. Pick with the
+ // following preference order: user selection over implicit one,
+ // source package over a system one, newer version over an older
+ // one. So get the preferred to try into p1 and the other to try
+ // -- into p2.
//
- if (p2->available_version () > p1->available_version ())
+ int us (p1->user_selection () - p2->user_selection ());
+ int sf (p1->system - p2->system);
+
+ if (us < 0 ||
+ (us == 0 && sf > 0) ||
+ (us == 0 &&
+ sf == 0 &&
+ p2->available_version () > p1->available_version ()))
swap (p1, p2);
// See if pv's version satisfies pc's constraints. Return the
diff --git a/tests/pkg-build.testscript b/tests/pkg-build.testscript
index a13d454..e06df77 100644
--- a/tests/pkg-build.testscript
+++ b/tests/pkg-build.testscript
@@ -792,10 +792,10 @@ test.options += --no-progress
$clone_cfg;
$* libfoo/1.0.0 libbaz 2>>EOE != 0
error: unable to satisfy constraints on package libfoo
- info: libbar depends on (libfoo == 1.1.0)
info: command line depends on (libfoo == 1.0.0)
- info: available libfoo/1.1.0
+ info: libbar depends on (libfoo == 1.1.0)
info: available libfoo/1.0.0
+ info: available libfoo/1.1.0
info: explicitly specify libfoo version to manually satisfy both constraints
info: while satisfying libbar/1.1.0
info: while satisfying libbaz/1.1.0
@@ -2297,6 +2297,52 @@ test.options += --no-progress
$pkg_drop libbar
}
+
+ : sys-to-src-unhold
+ :
+ {
+ $clone_cfg;
+
+ $* 'sys:libbaz/1.2.0' 2>>EOE;
+ configured sys:libbaz/1.2.0
+ EOE
+
+ $* ?libbaz libbar/0.0.3 2>>EOE;
+ purged libbaz/1.2.0
+ fetched libbaz/0.1.0
+ unpacked libbaz/0.1.0
+ fetched libbar/0.0.3
+ unpacked libbar/0.0.3
+ configured libbaz/0.1.0
+ configured libbar/0.0.3
+ EOE
+
+ $pkg_drop libbar libbaz
+ }
+
+ : sys-to-src
+ :
+ : As above but keep held.
+ :
+ {
+ $clone_cfg;
+
+ $* 'sys:libbaz/1.2.0' 2>>EOE;
+ configured sys:libbaz/1.2.0
+ EOE
+
+ $* libbaz libbar/0.0.3 2>>EOE;
+ purged libbaz/1.2.0
+ fetched libbaz/0.1.0
+ unpacked libbaz/0.1.0
+ fetched libbar/0.0.3
+ unpacked libbar/0.0.3
+ configured libbaz/0.1.0
+ configured libbar/0.0.3
+ EOE
+
+ $pkg_drop libbar libbaz
+ }
}
: source
diff --git a/tests/pkg-system.testscript b/tests/pkg-system.testscript
index 26d6893..3ff1b55 100644
--- a/tests/pkg-system.testscript
+++ b/tests/pkg-system.testscript
@@ -711,10 +711,10 @@ rep_remove += -d cfg 2>!
#
$pkg_build foo 'sys:libbar/1' 2>>EOE != 0;
error: unable to satisfy constraints on package libbar
- info: foo depends on (libbar >= 2)
info: command line depends on (libbar == 1)
- info: available sys:libbar/2
+ info: foo depends on (libbar >= 2)
info: available sys:libbar/1
+ info: available sys:libbar/2
info: explicitly specify libbar version to manually satisfy both constraints
info: while satisfying foo/2
EOE