From 546391dab6173660acceba6404136e9411ce1388 Mon Sep 17 00:00:00 2001 From: Boris Kolpackov Date: Wed, 1 Feb 2023 11:42:31 +0200 Subject: Implement system package manager query and install support for Debian --- bpkg/system-package-manager.test.hxx | 104 +++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 bpkg/system-package-manager.test.hxx (limited to 'bpkg/system-package-manager.test.hxx') diff --git a/bpkg/system-package-manager.test.hxx b/bpkg/system-package-manager.test.hxx new file mode 100644 index 0000000..0eb6717 --- /dev/null +++ b/bpkg/system-package-manager.test.hxx @@ -0,0 +1,104 @@ +// file : bpkg/system-package-manager.test.hxx -*- C++ -*- +// license : MIT; see accompanying LICENSE file + +#ifndef BPKG_SYSTEM_PACKAGE_MANAGER_TEST_HXX +#define BPKG_SYSTEM_PACKAGE_MANAGER_TEST_HXX + +#include + +#include // sort() + +#include +#include + +#include + +#include + +#include + +namespace bpkg +{ + // Parse the manifest as if it comes from a git repository with a single + // package and make an available package out of it. + // + inline + pair, lazy_shared_ptr> + make_available_from_manifest (const string& n, const string& f) + { + using butl::manifest_parser; + using butl::manifest_parsing; + + try + { + ifdstream ifs (f); + manifest_parser mp (ifs, f); + + package_manifest m (mp, + false /* ignore_unknown */, + true /* complete_values */); + + assert (m.name.string () == n); + + m.alt_naming = false; + m.bootstrap_build = "project = " + n + '\n'; + + shared_ptr ap ( + make_shared (move (m))); + + lazy_shared_ptr af ( + make_shared ( + repository_location ("https://example.com/" + n, + repository_type::git))); + + ap->locations.push_back (package_location {af, current_dir}); + + return make_pair (move (ap), move (af)); + } + catch (const manifest_parsing& e) + { + fail (e.name, e.line, e.column) << e.description << endf; + } + catch (const io_error& e) + { + fail << "unable to read from " << f << ": " << e << endf; + } + } + + // Make an available stub package as if it comes from git repository with + // a single package. + // + inline + pair, lazy_shared_ptr> + make_available_stub (const string& n) + { + shared_ptr ap ( + make_shared (package_name (n))); + + lazy_shared_ptr af ( + make_shared ( + repository_location ("https://example.com/" + n, + repository_type::git))); + + ap->locations.push_back (package_location {af, current_dir}); + + return make_pair (move (ap), move (af)); + } + + // Sort available packages in the version descending order. + // + inline void + sort_available (available_packages& aps) + { + using element_type = + pair, lazy_shared_ptr>; + + std::sort (aps.begin (), aps.end (), + [] (const element_type& x, const element_type& y) + { + return x.first->version > y.first->version; + }); + } +} + +#endif // BPKG_SYSTEM_PACKAGE_MANAGER_TEST_HXX -- cgit v1.1