aboutsummaryrefslogtreecommitdiff
path: root/bpkg/package.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2019-10-22 22:49:19 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2019-10-31 17:33:32 +0300
commitdad48d98b1a57706179c34853950588ec75a8467 (patch)
tree307cf55b44e88b2f6cc154c58cc74683040000ca /bpkg/package.cxx
parent6bbf6390d95941cd5ead6eba649edc2a7fec9d21 (diff)
Add support for package version constraint in pkg-build command arguments
Also document tests, examples, and benchmarks package manifest values.
Diffstat (limited to 'bpkg/package.cxx')
-rw-r--r--bpkg/package.cxx34
1 files changed, 34 insertions, 0 deletions
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<version_constraint>& 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
+ // "<name>/<version>" string rather than "<name> == <version>", using the
+ // version type-based overload.
+ //
+ const optional<version>& 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::