From 105524ed96f162b43c0735a65fea284d07356aa2 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Mon, 22 Jun 2020 19:05:08 +0300 Subject: Adapt to merging of package external tests, examples, and benchmarks into typed tests --- libbrep/build-extra.sql | 64 +++++++------------------------- libbrep/build-package.hxx | 16 +++----- libbrep/build.hxx | 2 +- libbrep/build.xml | 2 + libbrep/package.cxx | 6 +-- libbrep/package.hxx | 43 ++++++++++++++------- libbrep/package.xml | 74 +++++++++++++++++++++++++++++++++++++ load/load.cxx | 65 +++++++++++--------------------- migrate/migrate.cxx | 11 ++++++ mod/mod-build-task.cxx | 53 ++++++++++++-------------- mod/mod-package-version-details.cxx | 51 ++++++++++++++++++------- tests/load/driver.cxx | 2 +- 12 files changed, 219 insertions(+), 170 deletions(-) diff --git a/libbrep/build-extra.sql b/libbrep/build-extra.sql index b466382..a61f415 100644 --- a/libbrep/build-extra.sql +++ b/libbrep/build-extra.sql @@ -10,10 +10,6 @@ DROP FOREIGN TABLE IF EXISTS build_package_constraints; DROP FOREIGN TABLE IF EXISTS build_package_builds; -DROP FOREIGN TABLE IF EXISTS build_package_benchmarks; - -DROP FOREIGN TABLE IF EXISTS build_package_examples; - DROP FOREIGN TABLE IF EXISTS build_package_tests; DROP FOREIGN TABLE IF EXISTS build_package; @@ -22,6 +18,12 @@ DROP FOREIGN TABLE IF EXISTS build_repository; DROP FOREIGN TABLE IF EXISTS build_tenant; +-- @@ TMP Also drop tables that are removed in 12 schema version. Drop these +-- statements after 0.13.0 is released. +-- +DROP FOREIGN TABLE IF EXISTS build_package_benchmarks; +DROP FOREIGN TABLE IF EXISTS build_package_examples; + -- The foreign table for build_tenant object. -- CREATE FOREIGN TABLE build_tenant ( @@ -66,55 +68,15 @@ CREATE FOREIGN TABLE build_package_tests ( version_canonical_release TEXT NOT NULL COLLATE "C", version_revision INTEGER NOT NULL, index BIGINT NOT NULL, - dep_name CITEXT NOT NULL, - dep_package_tenant TEXT NULL, - dep_package_name CITEXT NULL, - dep_package_version_epoch INTEGER NULL, - dep_package_version_canonical_upstream TEXT NULL, - dep_package_version_canonical_release TEXT NULL COLLATE "C", - dep_package_version_revision INTEGER NULL) + test_name CITEXT NOT NULL, + test_package_tenant TEXT NULL, + test_package_name CITEXT NULL, + test_package_version_epoch INTEGER NULL, + test_package_version_canonical_upstream TEXT NULL, + test_package_version_canonical_release TEXT NULL COLLATE "C", + test_package_version_revision INTEGER NULL) SERVER package_server OPTIONS (table_name 'package_tests'); --- The foreign table for the build_package object examples member (that is of a --- container type). --- -CREATE FOREIGN TABLE build_package_examples ( - tenant TEXT NOT NULL, - name CITEXT NOT NULL, - version_epoch INTEGER NOT NULL, - version_canonical_upstream TEXT NOT NULL, - version_canonical_release TEXT NOT NULL COLLATE "C", - version_revision INTEGER NOT NULL, - index BIGINT NOT NULL, - dep_name CITEXT NOT NULL, - dep_package_tenant TEXT NULL, - dep_package_name CITEXT NULL, - dep_package_version_epoch INTEGER NULL, - dep_package_version_canonical_upstream TEXT NULL, - dep_package_version_canonical_release TEXT NULL COLLATE "C", - dep_package_version_revision INTEGER NULL) -SERVER package_server OPTIONS (table_name 'package_examples'); - --- The foreign table for the build_package object benchmarks member (that is --- of a container type). --- -CREATE FOREIGN TABLE build_package_benchmarks ( - tenant TEXT NOT NULL, - name CITEXT NOT NULL, - version_epoch INTEGER NOT NULL, - version_canonical_upstream TEXT NOT NULL, - version_canonical_release TEXT NOT NULL COLLATE "C", - version_revision INTEGER NOT NULL, - index BIGINT NOT NULL, - dep_name CITEXT NOT NULL, - dep_package_tenant TEXT NULL, - dep_package_name CITEXT NULL, - dep_package_version_epoch INTEGER NULL, - dep_package_version_canonical_upstream TEXT NULL, - dep_package_version_canonical_release TEXT NULL COLLATE "C", - dep_package_version_revision INTEGER NULL) -SERVER package_server OPTIONS (table_name 'package_benchmarks'); - -- The foreign table for the build_package object builds member (that is of a -- container type). -- diff --git a/libbrep/build-package.hxx b/libbrep/build-package.hxx index 228c5c0..09ec41d 100644 --- a/libbrep/build-package.hxx +++ b/libbrep/build-package.hxx @@ -72,10 +72,10 @@ namespace brep // class build_package; - // Build package test dependency. + // Build package external test dependency. // #pragma db value - struct build_dependency + struct build_test_dependency { package_name name; lazy_shared_ptr package; @@ -90,12 +90,10 @@ namespace brep package_id id; upstream_version version; - // Mapped to the package object tests, examples, and benchmarks members - // using the PostgreSQL foreign table mechanism. + // Mapped to the package object tests member using the PostgreSQL foreign + // table mechanism. // - small_vector tests; - small_vector examples; - small_vector benchmarks; + small_vector tests; lazy_shared_ptr internal_repository; bool buildable; @@ -117,9 +115,7 @@ namespace brep // #pragma db member(id) id column("") #pragma db member(version) set(this.version.init (this.id.version, (?))) - #pragma db member(tests) id_column("") value_column("dep_") - #pragma db member(examples) id_column("") value_column("dep_") - #pragma db member(benchmarks) id_column("") value_column("dep_") + #pragma db member(tests) id_column("") value_column("test_") #pragma db member(builds) id_column("") value_column("") #pragma db member(constraints) id_column("") value_column("") diff --git a/libbrep/build.hxx b/libbrep/build.hxx index a883fa0..1041805 100644 --- a/libbrep/build.hxx +++ b/libbrep/build.hxx @@ -25,7 +25,7 @@ // #define LIBBREP_BUILD_SCHEMA_VERSION_BASE 9 -#pragma db model version(LIBBREP_BUILD_SCHEMA_VERSION_BASE, 11, closed) +#pragma db model version(LIBBREP_BUILD_SCHEMA_VERSION_BASE, 12, closed) // We have to keep these mappings at the global scope instead of inside // the brep namespace because they need to be also effective in the diff --git a/libbrep/build.xml b/libbrep/build.xml index f4ba6cb..03d60e7 100644 --- a/libbrep/build.xml +++ b/libbrep/build.xml @@ -1,4 +1,6 @@ + + diff --git a/libbrep/package.cxx b/libbrep/package.cxx index 5ec1b69..564fec7 100644 --- a/libbrep/package.cxx +++ b/libbrep/package.cxx @@ -72,9 +72,7 @@ namespace brep optional bee, dependencies_type dp, requirements_type rq, - small_vector ts, - small_vector es, - small_vector bms, + small_vector ts, build_class_exprs bs, build_constraints_type bc, optional lc, @@ -107,8 +105,6 @@ namespace brep dependencies (move (dp)), requirements (move (rq)), tests (move (ts)), - examples (move (es)), - benchmarks (move (bms)), builds (move (bs)), build_constraints (move (bc)), internal_repository (move (rp)), diff --git a/libbrep/package.hxx b/libbrep/package.hxx index 0ab8413..e249573 100644 --- a/libbrep/package.hxx +++ b/libbrep/package.hxx @@ -20,7 +20,7 @@ // #define LIBBREP_PACKAGE_SCHEMA_VERSION_BASE 17 -#pragma db model version(LIBBREP_PACKAGE_SCHEMA_VERSION_BASE, 18, closed) +#pragma db model version(LIBBREP_PACKAGE_SCHEMA_VERSION_BASE, 19, open) namespace brep { @@ -181,6 +181,30 @@ namespace brep #pragma db value(requirement_alternatives) definition + // tests + // + using bpkg::test_dependency_type; + using bpkg::to_test_dependency_type; + + #pragma db map type(test_dependency_type) as(string) \ + to(to_string (?)) \ + from(brep::to_test_dependency_type (?)) + + #pragma db value + struct test_dependency: dependency + { + test_dependency_type type; + + test_dependency () = default; + test_dependency (package_name n, + test_dependency_type t, + optional c) + : dependency {std::move (n), std::move (c), nullptr /* package */}, + type (t) + { + } + }; + // certificate // #pragma db value @@ -386,9 +410,7 @@ namespace brep optional build_error_email, dependencies_type, requirements_type, - small_vector tests, - small_vector examples, - small_vector benchmarks, + small_vector tests, build_class_exprs, build_constraints_type, optional location, @@ -459,9 +481,7 @@ namespace brep optional build_error_email; dependencies_type dependencies; requirements_type requirements; - small_vector tests; // Note: foreign-mapped in build. - small_vector examples; // Note: foreign-mapped in build. - small_vector benchmarks; // Note: foreign-mapped in build. + small_vector tests; // Note: foreign-mapped in build. build_class_exprs builds; // Note: foreign-mapped in build. build_constraints_type build_constraints; // Note: foreign-mapped in build. @@ -563,14 +583,9 @@ namespace brep set(odb::nested_set (this.requirements, std::move (?))) \ id_column("") key_column("") value_column("id") - // tests, examples, benchmarks - // - // Seeing that these reuse the dependency types, we are also going to - // have identical database mapping. + // tests // - #pragma db member(tests) id_column("") value_column("dep_") - #pragma db member(examples) id_column("") value_column("dep_") - #pragma db member(benchmarks) id_column("") value_column("dep_") + #pragma db member(tests) id_column("") value_column("test_") // builds // diff --git a/libbrep/package.xml b/libbrep/package.xml index 12ae36e..e650555 100644 --- a/libbrep/package.xml +++ b/libbrep/package.xml @@ -1,4 +1,78 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/load/load.cxx b/load/load.cxx index b289829..e6591f5 100644 --- a/load/load.cxx +++ b/load/load.cxx @@ -500,30 +500,25 @@ load_packages (const shared_ptr& rp, ds.emplace_back (pda.conditional, pda.buildtime, move (pda.comment)); for (auto& pd: pda) + { // The package member will be assigned during dependency // resolution procedure. // ds.back ().push_back (dependency {move (pd.name), move (pd.constraint), nullptr /* package */}); + } } - auto deps = [] (small_vector&& ds) - { - small_vector r; + small_vector ts; - if (!ds.empty ()) - { - r.reserve (ds.size ()); - - for (bpkg::dependency& d: ds) - r.push_back (dependency {move (d.name), - move (d.constraint), - nullptr /* package */}); - } + if (!pm.tests.empty ()) + { + ts.reserve (pm.tests.size ()); - return r; - }; + for (bpkg::test_dependency& td: pm.tests) + ts.emplace_back (move (td.name), td.type, move (td.constraint)); + } // Cache before the package name is moved. // @@ -553,9 +548,7 @@ load_packages (const shared_ptr& rp, move (pm.build_error_email), move (ds), move (pm.requirements), - deps (move (pm.tests)), - deps (move (pm.examples)), - deps (move (pm.benchmarks)), + move (ts), move (pm.builds), move (pm.build_constraints), move (pm.location), @@ -858,14 +851,13 @@ find (const lazy_shared_ptr& r, return false; } -// Resolve package run-time dependencies, tests, examples, and benchmarks. -// Make sure that the best matching dependency belongs to the package -// repositories, their complements, recursively, or their immediate -// prerequisite repositories (only for run-time dependencies). Set the -// buildable flag to false for the resolved tests, examples, and benchmarks -// packages. Fail if unable to resolve a dependency, unless ignore_unresolved -// is true in which case leave this dependency NULL. Should be called once per -// internal package. +// Resolve package run-time dependencies and external tests. Make sure that +// the best matching dependency belongs to the package repositories, their +// complements, recursively, or their immediate prerequisite repositories +// (only for run-time dependencies). Set the buildable flag to false for the +// resolved external tests packages. Fail if unable to resolve a dependency, +// unless ignore_unresolved is true in which case leave this dependency +// NULL. Should be called once per internal package. // static void resolve_dependencies (package& p, database& db, bool ignore_unresolved) @@ -877,10 +869,7 @@ resolve_dependencies (package& p, database& db, bool ignore_unresolved) // assert (p.internal ()); - if (p.dependencies.empty () && - p.tests.empty () && - p.examples.empty () && - p.benchmarks.empty ()) + if (p.dependencies.empty () && p.tests.empty ()) return; auto resolve = [&p, &db] (dependency& d, bool test) @@ -996,22 +985,10 @@ resolve_dependencies (package& p, database& db, bool ignore_unresolved) } } - for (dependency& d: p.tests) - { - if (!resolve (d, true /* test */) && !ignore_unresolved) - bail (d, "tests"); - } - - for (dependency& d: p.examples) - { - if (!resolve (d, true /* test */) && !ignore_unresolved) - bail (d, "examples"); - } - - for (dependency& d: p.benchmarks) + for (brep::test_dependency& td: p.tests) { - if (!resolve (d, true /* test */) && !ignore_unresolved) - bail (d, "benchmarks"); + if (!resolve (td, true /* test */) && !ignore_unresolved) + bail (td, td.name.string ().c_str ()); } db.update (p); // Update the package state. diff --git a/migrate/migrate.cxx b/migrate/migrate.cxx index feac683..0ef6096 100644 --- a/migrate/migrate.cxx +++ b/migrate/migrate.cxx @@ -237,6 +237,17 @@ package_migrate_v18 ([] (database& db) }); //#endif +// Merging the package examples and benchmarks tables into the package tests +// table is a bit hairy. Thus, we won't bother with that and just cleanup the +// amended package tests table, relying on the loader to fill it in a short +// time. +// +static const package_migration_entry<19> +package_migrate_v19 ([] (database& db) +{ + db.execute ("DELETE from package_tests"); +}); + // main() function // int diff --git a/mod/mod-build-task.cxx b/mod/mod-build-task.cxx index 741d3b4..04b2a36 100644 --- a/mod/mod-build-task.cxx +++ b/mod/mod-build-task.cxx @@ -228,40 +228,33 @@ handle (request& rq, response& rs) // configuration. // small_vector tes; - auto add_exclusions = [&tes, &cm, this] - (const small_vector& tests) + + for (const build_test_dependency& td: p->tests) { - for (const build_dependency& t: tests) + // Don't exclude unresolved external tests. + // + // Note that this may result in the build task failure. However, + // silently excluding such tests could end up with missed software + // bugs which feels much worse. + // + if (td.package != nullptr) { - // Don't exclude unresolved external tests. - // - // Note that this may result in the build task failure. However, - // silently excluding such tests could end up with missed software - // bugs which feels much worse. - // - if (t.package != nullptr) - { - shared_ptr p (t.package.load ()); + shared_ptr p (td.package.load ()); - // Use the `all` class as a least restrictive default underlying - // build class set. Note that we should only apply the explicit - // build restrictions to the external test packages (think about - // the `builds: all` and `builds: -windows` manifest values for - // the primary and external test packages, respectively). - // - if (exclude (p->builds, - p->constraints, - *cm.config, - nullptr /* reason */, - true /* default_all_ucs */)) - tes.push_back (package {move (p->id.name), move (p->version)}); - } + // Use the `all` class as a least restrictive default underlying + // build class set. Note that we should only apply the explicit + // build restrictions to the external test packages (think about + // the `builds: all` and `builds: -windows` manifest values for + // the primary and external test packages, respectively). + // + if (exclude (p->builds, + p->constraints, + *cm.config, + nullptr /* reason */, + true /* default_all_ucs */)) + tes.push_back (package {move (p->id.name), move (p->version)}); } - }; - - add_exclusions (p->tests); - add_exclusions (p->examples); - add_exclusions (p->benchmarks); + } task_manifest task (move (b->package_name), move (b->package_version), diff --git a/mod/mod-package-version-details.cxx b/mod/mod-package-version-details.cxx index bfc08b0..a7682ec 100644 --- a/mod/mod-package-version-details.cxx +++ b/mod/mod-package-version-details.cxx @@ -397,38 +397,61 @@ handle (request& rq, response& rs) << ~TABLE; } - auto print_dependencies = [&s, &print_dependency] - (const small_vector& deps, - const char* heading, - const char* id) + // Print the test dependencies grouped by types as the separate blocks. + // + // Print test dependencies of the specific type. + // + auto print_tests = [&pkg, &s, &print_dependency] (test_dependency_type dt) { - if (!deps.empty ()) - { - s << H3 << heading << ~H3 - << TABLE(CLASS="proplist", ID=id) - << TBODY; + string id; - for (const dependency& d: deps) + bool first (true); + for (const test_dependency& td: pkg->tests) + { + if (td.type == dt) { + // Print the table header if this is a first test dependency. + // + if (first) + { + id = to_string (dt); + + // Capitalize the heading. + // + string heading (id); + heading[0] = ucase (id[0]); + + s << H3 << heading << ~H3 + << TABLE(CLASS="proplist", ID=id) + << TBODY; + + first = false; + } + s << TR(CLASS=id) << TD << SPAN(CLASS="value"); - print_dependency (d); + print_dependency (td); s << ~SPAN << ~TD << ~TR; } + } + // Print the table closing tags if it was printed. + // + if (!first) + { s << ~TBODY << ~TABLE; } }; - print_dependencies (pkg->tests, "Tests", "tests"); - print_dependencies (pkg->examples, "Examples", "examples"); - print_dependencies (pkg->benchmarks, "Benchmarks", "benchmarks"); + print_tests (test_dependency_type::tests); + print_tests (test_dependency_type::examples); + print_tests (test_dependency_type::benchmarks); bool builds (build_db_ != nullptr && pkg->buildable); diff --git a/tests/load/driver.cxx b/tests/load/driver.cxx index 420c1e3..b4c43cc 100644 --- a/tests/load/driver.cxx +++ b/tests/load/driver.cxx @@ -204,7 +204,7 @@ main (int argc, char* argv[]) static inline dependency dep (const char* n, optional c) { - return dependency {package_name (n), move (c), nullptr}; + return dependency {package_name (n), move (c), nullptr /* package */}; } static inline version -- cgit v1.1