aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Kolpackov <boris@codesynthesis.com>2016-01-25 15:44:02 +0200
committerBoris Kolpackov <boris@codesynthesis.com>2016-01-25 15:44:02 +0200
commitffab0e52df6609050f19f0cbd31b2f7d7d2daa1b (patch)
tree073072acae6dad96ef95c2acd61a9f27f9c91214
parentbe63c7bb20645c0e3ba0d3b3b0ac3ca8692fb237 (diff)
Add extra diagnostics if argument doesn't look like package name/version
-rw-r--r--bpkg/pkg-build.cxx62
1 files changed, 47 insertions, 15 deletions
diff --git a/bpkg/pkg-build.cxx b/bpkg/pkg-build.cxx
index 8026308..6202095 100644
--- a/bpkg/pkg-build.cxx
+++ b/bpkg/pkg-build.cxx
@@ -761,9 +761,18 @@ namespace bpkg
shared_ptr<repository> root (db.load<repository> (""));
- while (args.more ())
+ // Here is what happens here: are are going to try and guess whether we
+ // are dealing with a package archive, package directory, or package
+ // name/version by first trying it as an archive, then as a directory,
+ // and then assume it is name/version. Sometimes, however, it is really
+ // one of the first two but just broken. In this case things are really
+ // confusing since we suppress all diagnostics for the first two
+ // "guesses". So what we are going to do here is re-run them with full
+ // diagnostics if the name/version guess doesn't pan out.
+ //
+ for (bool diag (false); args.more (); )
{
- const char* s (args.next ());
+ const char* s (args.peek ());
// Reduce all the potential variations (archive, directory, package
// name, package name/version) to a single available_package object.
@@ -781,7 +790,11 @@ namespace bpkg
path a (s);
if (exists (a))
{
- package_manifest m (pkg_verify (o, a, true, false));
+ if (diag)
+ info << "'" << s << "' does not appear to be a valid package "
+ << "archive: ";
+
+ package_manifest m (pkg_verify (o, a, true, diag));
// This is a package archive (note that we shouldn't throw
// failed from here on).
@@ -810,7 +823,11 @@ namespace bpkg
dir_path d (s);
if (exists (d))
{
- package_manifest m (pkg_verify (d, true, false));
+ if (diag)
+ info << "'" << s << "' does not appear to be a valid package "
+ << "directory: ";
+
+ package_manifest m (pkg_verify (d, true, diag));
// This is a package directory (note that we shouldn't throw
// failed from here on).
@@ -832,25 +849,40 @@ namespace bpkg
// Not a valid package archive.
}
+ // If this was a diagnostics "run", then we are done.
+ //
+ if (diag)
+ throw failed ();
+
// Then it got to be a package name with optional version.
//
if (ap == nullptr)
{
- n = parse_package_name (s);
- v = parse_package_version (s);
- level4 ([&]{trace << "package " << n << "; version " << v;});
+ try
+ {
+ n = parse_package_name (s);
+ v = parse_package_version (s);
+ level4 ([&]{trace << "package " << n << "; version " << v;});
- // Either get the user-specified version or the latest.
- //
- auto rp (
- v.empty ()
- ? find_available (db, n, root, nullopt)
- : find_available (db, n, root, dependency_constraint (v)));
+ // Either get the user-specified version or the latest.
+ //
+ auto rp (
+ v.empty ()
+ ? find_available (db, n, root, nullopt)
+ : find_available (db, n, root, dependency_constraint (v)));
- ap = rp.first;
- ar = rp.second;
+ ap = rp.first;
+ ar = rp.second;
+ }
+ catch (const failed&)
+ {
+ diag = true;
+ continue;
+ }
}
+ args.next (); // We are handling this argument.
+
// Load the package that may have already been selected and
// figure out what exactly we need to do here. The end goal
// is the available_package object corresponding to the actual