aboutsummaryrefslogtreecommitdiff
path: root/libbpkg/manifest.cxx
diff options
context:
space:
mode:
authorKaren Arutyunov <karen@codesynthesis.com>2020-06-20 18:54:44 +0300
committerKaren Arutyunov <karen@codesynthesis.com>2020-06-26 13:50:16 +0300
commitbdb86456ec665f4367bc1caf52902a3a3a4fbbed (patch)
treec6e6227920555ceaa1b8c86b585faeed466202d4 /libbpkg/manifest.cxx
parent41c2026a10be5fc73986eba037fac6993d5cdb64 (diff)
Merge package external test, example, and benchmark dependencies into typed test dependency
Diffstat (limited to 'libbpkg/manifest.cxx')
-rw-r--r--libbpkg/manifest.cxx90
1 files changed, 54 insertions, 36 deletions
diff --git a/libbpkg/manifest.cxx b/libbpkg/manifest.cxx
index 9caa229..4a104f4 100644
--- a/libbpkg/manifest.cxx
+++ b/libbpkg/manifest.cxx
@@ -1511,6 +1511,31 @@ namespace bpkg
return r;
}
+ // test_dependency_type
+ //
+ string
+ to_string (test_dependency_type t)
+ {
+ switch (t)
+ {
+ case test_dependency_type::tests: return "tests";
+ case test_dependency_type::examples: return "examples";
+ case test_dependency_type::benchmarks: return "benchmarks";
+ }
+
+ assert (false); // Can't be here.
+ return string ();
+ }
+
+ test_dependency_type
+ to_test_dependency_type (const string& t)
+ {
+ if (t == "tests") return test_dependency_type::tests;
+ else if (t == "examples") return test_dependency_type::examples;
+ else if (t == "benchmarks") return test_dependency_type::benchmarks;
+ else throw invalid_argument ("invalid test dependency type '" + t + "'");
+ }
+
// pkg_package_manifest
//
static build_class_expr
@@ -1716,14 +1741,12 @@ namespace bpkg
//
optional<name_value> upstream_version;
- // We will cache the depends, tests, examples, and benchmarks manifest
- // values to parse and, if requested, complete the version constraints
- // later, after the version value is parsed.
+ // We will cache the depends and the test dependency manifest values to
+ // parse and, if requested, complete the version constraints later, after
+ // the version value is parsed.
//
vector<name_value> dependencies;
small_vector<name_value, 1> tests;
- small_vector<name_value, 1> examples;
- small_vector<name_value, 1> benchmarks;
// We will cache the description and its type values to validate them
// later, after both are parsed.
@@ -2040,18 +2063,10 @@ namespace bpkg
{
dependencies.push_back (move (nv));
}
- else if (n == "tests")
+ else if (n == "tests" || n == "examples" || n == "benchmarks")
{
tests.push_back (move (nv));
}
- else if (n == "examples")
- {
- examples.push_back (move (nv));
- }
- else if (n == "benchmarks")
- {
- benchmarks.push_back (move (nv));
- }
else if (n == "location")
{
if (flag (package_manifest_flags::forbid_location))
@@ -2201,8 +2216,7 @@ namespace bpkg
}
// Now, when the version manifest value is parsed, we can parse the
- // dependencies, tests, examples, and benchmarks and complete their
- // constraints, if requested.
+ // dependencies and complete their constraints, if requested.
//
auto parse_dependency = [&m, cd, &flag, &bad_value] (string&& d,
const char* what)
@@ -2268,6 +2282,8 @@ namespace bpkg
return r;
};
+ // Parse the regular dependencies.
+ //
for (name_value& d: dependencies)
{
nv = move (d); // Restore as bad_value() uses its line/column.
@@ -2304,21 +2320,29 @@ namespace bpkg
m.dependencies.push_back (da);
}
- auto parse_deps = [&nv, &parse_dependency]
- (small_vector<name_value, 1>&& nvs, const char* what)
+ // Parse the test dependencies.
+ //
+ for (name_value& v: tests)
{
- small_vector<dependency, 1> r;
- for (name_value& v: nvs)
+ nv = move (v); // Restore as bad_value() uses its line/column.
+
+ dependency d (parse_dependency (move (nv.value), nv.name.c_str ()));
+
+ try
{
- nv = move (v); // Restore as bad_value() uses its line/column.
- r.push_back (parse_dependency (move (nv.value), what));
+ m.tests.emplace_back (
+ move (d.name),
+ to_test_dependency_type (nv.name),
+ move (d.constraint));
}
- return r;
- };
-
- m.tests = parse_deps (move (tests), "tests");
- m.examples = parse_deps (move (examples), "examples");
- m.benchmarks = parse_deps (move (benchmarks), "benchmarks");
+ catch (const invalid_argument&)
+ {
+ // to_test_dependency_type() can't throw since the type string is
+ // already validated.
+ //
+ assert (false);
+ }
+ }
if (m.description &&
!m.description_type &&
@@ -2699,14 +2723,8 @@ namespace bpkg
: (r.buildtime ? "* " : "")) +
serializer::merge_comment (concatenate (r, " | "), r.comment));
- for (const dependency& t: m.tests)
- s.next ("tests", t.string ());
-
- for (const dependency& t: m.examples)
- s.next ("examples", t.string ());
-
- for (const dependency& t: m.benchmarks)
- s.next ("benchmarks", t.string ());
+ for (const test_dependency& p: m.tests)
+ s.next (to_string (p.type), p.string ());
for (const build_class_expr& e: m.builds)
s.next ("builds", serializer::merge_comment (e.string (), e.comment));