From 61f62a91bdf0348a73db18b95a6e9aa475aa6568 Mon Sep 17 00:00:00 2001 From: Karen Arutyunov Date: Thu, 26 Jan 2023 14:25:04 +0300 Subject: Create available packages in debian system package manager test and pass --sys-no-query for pkg-build in testscripts --- bpkg/system-package-manager-debian.test.cxx | 69 +++++++++++++++++++++++++++-- bpkg/system-package-manager.cxx | 41 +++++++++++++---- tests/common.testscript | 4 +- tests/pkg-build.testscript | 4 ++ tests/pkg-drop.testscript | 4 +- 5 files changed, 109 insertions(+), 13 deletions(-) diff --git a/bpkg/system-package-manager-debian.test.cxx b/bpkg/system-package-manager-debian.test.cxx index a1cdbe3..bdf6245 100644 --- a/bpkg/system-package-manager-debian.test.cxx +++ b/bpkg/system-package-manager-debian.test.cxx @@ -9,6 +9,12 @@ #include #include +#include + +#include + +#include + #undef NDEBUG #include @@ -19,6 +25,9 @@ namespace bpkg using package_status = system_package_status_debian; using package_policy = package_status::package_policy; + using butl::manifest_parser; + using butl::manifest_parsing; + // Usage: args[0] ... // // Where is one of: @@ -210,7 +219,41 @@ namespace bpkg if (i == aps.end ()) fail << "unknown package " << n << " in '" << l << "'"; - // @@ TODO: parse manifest and make available package out of it. + // Parse the manifest as if it comes from a git repository with a + // single package and make an available package out of it. + // + try + { + ifdstream ifs (f); + manifest_parser mp (ifs, f); + + package_manifest m (mp, + false /* ignore_unknown */, + true /* complete_values */); + + m.alt_naming = false; + m.bootstrap_build = "project = " + m.name.string () + '\n'; + + shared_ptr ap ( + make_shared (move (m))); + + lazy_shared_ptr af ( + make_shared ( + repository_location ("https://example.com/" + i->first, + repository_type::git))); + + ap->locations.push_back (package_location {af, current_dir}); + + i->second.push_back (make_pair (move (ap), move (af))); + } + catch (const manifest_parsing& e) + { + fail (e.name, e.line, e.column) << e.description; + } + catch (const io_error& e) + { + fail << "unable to read from " << f << ": " << e; + } } else if ( map* policy = @@ -262,13 +305,33 @@ namespace bpkg fail << "unknown keyword '" << k << "' in simulation description"; } - // Fallback to stubs. + // Fallback to stubs as if they come from git repositories with a single + // package. // for (pair& p: aps) { if (p.second.empty ()) { - // @@ TODO: add stub available package. + try + { + package_name n (p.first); + + shared_ptr ap ( + make_shared (move (n))); + + lazy_shared_ptr af ( + make_shared ( + repository_location ("https://example.com/" + p.first, + repository_type::git))); + + ap->locations.push_back (package_location {af, current_dir}); + + p.second.push_back (make_pair (move (ap), move (af))); + } + catch (const invalid_argument& e) + { + fail << "invalid package name '" << p.first << "': " << e; + } } } diff --git a/bpkg/system-package-manager.cxx b/bpkg/system-package-manager.cxx index 5e556f9..e31f0ac 100644 --- a/bpkg/system-package-manager.cxx +++ b/bpkg/system-package-manager.cxx @@ -155,10 +155,22 @@ namespace bpkg } catch (const invalid_argument& e) { - fail << "invalid distribution version '" << string (dn, p + 1) - << "' in value " << value_name << " for package " << ap->id.name - << ' ' << ap->version << af.database () << " in repository " - << af.load ()->location << ": " << e; + // Note: the repository fragment may have no database associated when + // used in tests. + // + shared_ptr f (af.get_eager ()); + database* db (f == nullptr || af.loaded () ? &af.database () : nullptr); + + diag_record dr (fail); + dr << "invalid distribution version '" << string (dn, p + 1) + << "' in value " << value_name << " for package " << ap->id.name + << ' ' << ap->version; + + if (db != nullptr) + dr << *db; + + dr << " in repository " << (f != nullptr ? f : af.load ())->location + << ": " << e; } return make_pair (move (dn), move (dv)); @@ -297,12 +309,25 @@ namespace bpkg { auto bad_value = [&nv, &ap, &a] (const string& d) { + // Note: the repository fragment may have no database + // associated when used in tests. + // const lazy_shared_ptr& af (a.second); + shared_ptr f (af.get_eager ()); + database* db (f == nullptr || af.loaded () + ? &af.database () + : nullptr); + + diag_record dr (fail); + dr << "invalid distribution value '" << nv.name << ": " + << nv.value << "' for package " << ap->id.name << ' ' + << ap->version; + + if (db != nullptr) + dr << *db; - fail << "invalid distribution value '" << nv.name << ": " - << nv.value << "' for package " << ap->id.name << ' ' - << ap->version << af.database () << " in repository " - << af.load ()->location << ": " << d; + dr << " in repository " + << (f != nullptr ? f : af.load ())->location << ": " << d; }; // Parse the distribution value into the regex pattern and the diff --git a/tests/common.testscript b/tests/common.testscript index 17174d9..30fcf7e 100644 --- a/tests/common.testscript +++ b/tests/common.testscript @@ -32,11 +32,13 @@ test.options += --default-options $options_guard \ # (for example, to make sure that configuration post-test state is valid and is # as expected). # +# Disable the use of the system package manager for the pkg-build command. +# cfg_create = [cmdline] $* cfg-create cfg_info = [cmdline] $* cfg-info cfg_link = [cmdline] $* cfg-link cfg_unlink = [cmdline] $* cfg-unlink -pkg_build = [cmdline] $* pkg-build +pkg_build = [cmdline] $* pkg-build --sys-no-query pkg_checkout = [cmdline] $* pkg-checkout pkg_configure = [cmdline] $* pkg-configure pkg_disfigure = [cmdline] $* pkg-disfigure diff --git a/tests/pkg-build.testscript b/tests/pkg-build.testscript index 198e319..aaa7bc4 100644 --- a/tests/pkg-build.testscript +++ b/tests/pkg-build.testscript @@ -461,6 +461,10 @@ rep_list += -d cfg # test.options += --no-progress +# Disable the use of the system package manager. +# +test.arguments += --sys-no-query + : libfoo : : Test building different versions of libfoo. diff --git a/tests/pkg-drop.testscript b/tests/pkg-drop.testscript index a2e58f3..7504d6c 100644 --- a/tests/pkg-drop.testscript +++ b/tests/pkg-drop.testscript @@ -458,7 +458,9 @@ $* libfoo/1.0.0 2>>~%EOE% != 0 : linked-configs : { - pkg_build = [cmdline] $0 pkg-build --yes 2>! + # Get rid of -d option. + # + pkg_build = [cmdline] $0 pkg-build --yes --sys-no-query 2>! : 3-configs : -- cgit v1.1