From dad48d98b1a57706179c34853950588ec75a8467 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Tue, 22 Oct 2019 22:49:19 +0300 Subject: Add support for package version constraint in pkg-build command arguments Also document tests, examples, and benchmarks package manifest values. --- bpkg/package.cxx | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) (limited to 'bpkg/package.cxx') diff --git a/bpkg/package.cxx b/bpkg/package.cxx index 563fc93..e45718e 100644 --- a/bpkg/package.cxx +++ b/bpkg/package.cxx @@ -262,6 +262,40 @@ namespace bpkg return system ? "sys:" + n.string () + vs : n.string () + vs; } + string + package_string (const package_name& name, + const optional& constraint, + bool system) + { + // Fallback to the version type-based overload if the constraint is not + // specified. + // + if (!constraint) + return package_string (name, version (), system); + + // There are no scenarios where the version constrain is present but is + // empty (both endpoints are nullopt). + // + assert (!constraint->empty ()); + + // If the endpoint versions are equal then represent the constraint as the + // "/" string rather than " == ", using the + // version type-based overload. + // + const optional& min_ver (constraint->min_version); + bool eq (min_ver == constraint->max_version); + + if (eq) + return package_string (name, *min_ver, system); + + if (system) + return package_string (name, version (), system) + "/..."; + + // Quote the result as it contains the space character. + // + return "'" + name.string () + ' ' + constraint->string () + "'"; + } + // selected_package // string selected_package:: -- cgit v1.1