int build(const options& opts) { | int build(const options& opts) { | ||||
if (!opts.build.add_repos.empty()) { | if (!opts.build.add_repos.empty()) { | ||||
auto cat = opts.open_catalog(); | |||||
auto cat = opts.open_pkg_db(); | |||||
for (auto& str : opts.build.add_repos) { | for (auto& str : opts.build.add_repos) { | ||||
auto repo = pkg_remote::connect(str); | auto repo = pkg_remote::connect(str); | ||||
repo.store(cat.database()); | repo.store(cat.database()); | ||||
} | } | ||||
if (opts.build.update_repos || !opts.build.add_repos.empty()) { | if (opts.build.update_repos || !opts.build.add_repos.empty()) { | ||||
update_all_remotes(opts.open_catalog().database()); | |||||
update_all_remotes(opts.open_pkg_db().database()); | |||||
} | } | ||||
auto builder = create_project_builder(opts); | auto builder = create_project_builder(opts); |
auto all_deps = ranges::views::concat(all_file_deps, cmd_deps) | ranges::to_vector; | auto all_deps = ranges::views::concat(all_file_deps, cmd_deps) | ranges::to_vector; | ||||
auto cat = opts.open_catalog(); | |||||
auto cat = opts.open_pkg_db(); | |||||
dds::pkg_cache::with_cache( // | dds::pkg_cache::with_cache( // | ||||
opts.pkg_cache_dir.value_or(pkg_cache::default_local_path()), | opts.pkg_cache_dir.value_or(pkg_cache::default_local_path()), | ||||
dds::pkg_cache_flags::write_lock | dds::pkg_cache_flags::create_if_absent, | dds::pkg_cache_flags::write_lock | dds::pkg_cache_flags::create_if_absent, |
namespace dds::cli::cmd { | namespace dds::cli::cmd { | ||||
static int _pkg_get(const options& opts) { | static int _pkg_get(const options& opts) { | ||||
auto cat = opts.open_catalog(); | |||||
auto cat = opts.open_pkg_db(); | |||||
for (const auto& item : opts.pkg.get.pkgs) { | for (const auto& item : opts.pkg.get.pkgs) { | ||||
auto id = pkg_id::parse(item); | auto id = pkg_id::parse(item); | ||||
dds::dym_target dym; | dds::dym_target dym; |
namespace dds::cli::cmd { | namespace dds::cli::cmd { | ||||
static int _pkg_repo_add(const options& opts) { | static int _pkg_repo_add(const options& opts) { | ||||
auto cat = opts.open_catalog(); | |||||
auto cat = opts.open_pkg_db(); | |||||
auto repo = pkg_remote::connect(opts.pkg.repo.add.url); | auto repo = pkg_remote::connect(opts.pkg.repo.add.url); | ||||
repo.store(cat.database()); | repo.store(cat.database()); | ||||
if (opts.pkg.repo.add.update) { | if (opts.pkg.repo.add.update) { |
namespace dds::cli::cmd { | namespace dds::cli::cmd { | ||||
static int _pkg_repo_ls(const options& opts) { | static int _pkg_repo_ls(const options& opts) { | ||||
auto pkg_db = opts.open_catalog(); | |||||
auto pkg_db = opts.open_pkg_db(); | |||||
neo::sqlite3::database_ref db = pkg_db.database(); | neo::sqlite3::database_ref db = pkg_db.database(); | ||||
auto st = db.prepare("SELECT name, remote_url, db_mtime FROM dds_pkg_remotes"); | auto st = db.prepare("SELECT name, remote_url, db_mtime FROM dds_pkg_remotes"); |
namespace dds::cli::cmd { | namespace dds::cli::cmd { | ||||
static int _pkg_repo_update(const options& opts) { | static int _pkg_repo_update(const options& opts) { | ||||
update_all_remotes(opts.open_catalog().database()); | |||||
update_all_remotes(opts.open_pkg_db().database()); | |||||
return 0; | return 0; | ||||
} | } | ||||
setup{*this}.do_setup(parser); | setup{*this}.do_setup(parser); | ||||
} | } | ||||
pkg_db dds::cli::options::open_catalog() const { | |||||
pkg_db dds::cli::options::open_pkg_db() const { | |||||
return pkg_db::open(this->pkg_db_dir.value_or(pkg_db::default_path())); | return pkg_db::open(this->pkg_db_dir.value_or(pkg_db::default_path())); | ||||
} | } | ||||
* @brief Open the package pkg_db based on the user-specified options. | * @brief Open the package pkg_db based on the user-specified options. | ||||
* @return pkg_db | * @return pkg_db | ||||
*/ | */ | ||||
pkg_db open_catalog() const; | |||||
pkg_db open_pkg_db() const; | |||||
/** | /** | ||||
* @brief Load a dds toolchain as specified by the user, or a default. | * @brief Load a dds toolchain as specified by the user, or a default. | ||||
* @return dds::toolchain | * @return dds::toolchain |
dds::fs::remove_all(subdir); | dds::fs::remove_all(subdir); | ||||
} | } | ||||
class catalog_test_case { | |||||
public: | |||||
struct pkg_db_test_case { | |||||
dds::pkg_db db = dds::pkg_db::open(":memory:"s); | dds::pkg_db db = dds::pkg_db::open(":memory:"s); | ||||
}; | }; | ||||
TEST_CASE_METHOD(catalog_test_case, "Store a simple package") { | |||||
TEST_CASE_METHOD(pkg_db_test_case, "Store a simple package") { | |||||
db.store(dds::pkg_listing{ | db.store(dds::pkg_listing{ | ||||
dds::pkg_id{"foo", semver::version::parse("1.2.3")}, | dds::pkg_id{"foo", semver::version::parse("1.2.3")}, | ||||
{}, | {}, | ||||
CHECK(info->remote_pkg.to_url_string() == "git+http://example.com#develop"); | CHECK(info->remote_pkg.to_url_string() == "git+http://example.com#develop"); | ||||
} | } | ||||
TEST_CASE_METHOD(catalog_test_case, "Package requirements") { | |||||
TEST_CASE_METHOD(pkg_db_test_case, "Package requirements") { | |||||
db.store(dds::pkg_listing{ | db.store(dds::pkg_listing{ | ||||
dds::pkg_id{"foo", semver::version::parse("1.2.3")}, | dds::pkg_id{"foo", semver::version::parse("1.2.3")}, | ||||
{ | { |