Kaynağa Gözat

Move catalog to its own dir, and start adding subcommands for it

default_compile_flags
vector-of-bool 5 yıl önce
ebeveyn
işleme
955cb7acdb
4 değiştirilmiş dosya ile 110 ekleme ve 20 silme
  1. +13
    -12
      src/dds/catalog/catalog.cpp
  2. +0
    -0
      src/dds/catalog/catalog.hpp
  3. +1
    -1
      src/dds/catalog/catalog.test.cpp
  4. +96
    -7
      src/dds/dds.main.cpp

src/dds/repo/catalog.cpp → src/dds/catalog/catalog.cpp Dosyayı Görüntüle

@@ -19,7 +19,7 @@ namespace {

void migrate_repodb_1(sqlite3::database& db) {
db.exec(R"(
CREATE TABLE dds_repo_pkgs (
CREATE TABLE dds_cat_pkgs (
pkg_id INTEGER PRIMARY KEY AUTOINCREMENT,
name TEXT NOT NULL,
version TEXT NOT NULL,
@@ -39,17 +39,18 @@ void migrate_repodb_1(sqlite3::database& db) {
lm_name NOT NULL
AND lm_namespace NOT NULL
)
!=
+
(
lm_name ISNULL
AND lm_namespace ISNULL
)
= 1
)
);

CREATE TABLE dds_repo_pkg_deps (
CREATE TABLE dds_cat_pkg_deps (
dep_id INTEGER PRIMARY KEY AUTOINCREMENT,
pkg_id INTEGER NOT NULL REFERENCES dds_repo_pkgs(pkg_id),
pkg_id INTEGER NOT NULL REFERENCES dds_cat_pkgs(pkg_id),
dep_name TEXT NOT NULL,
low TEXT NOT NULL,
high TEXT NOT NULL,
@@ -62,11 +63,11 @@ void ensure_migrated(sqlite3::database& db) {
sqlite3::transaction_guard tr{db};
db.exec(R"(
PRAGMA foreign_keys = 1;
CREATE TABLE IF NOT EXISTS dds_repo_meta AS
CREATE TABLE IF NOT EXISTS dds_cat_meta AS
WITH init(meta) AS (VALUES ('{"version": 0}'))
SELECT * FROM init;
)");
auto meta_st = db.prepare("SELECT meta FROM dds_repo_meta");
auto meta_st = db.prepare("SELECT meta FROM dds_cat_meta");
auto [meta_json] = sqlite3::unpack_single<std::string>(meta_st);

auto meta = nlohmann::json::parse(meta_json);
@@ -83,7 +84,7 @@ void ensure_migrated(sqlite3::database& db) {
migrate_repodb_1(db);
}
meta["version"] = 1;
exec(db, "UPDATE dds_repo_meta SET meta=?", std::forward_as_tuple(meta.dump()));
exec(db, "UPDATE dds_cat_meta SET meta=?", std::forward_as_tuple(meta.dump()));
}

} // namespace
@@ -110,7 +111,7 @@ void catalog::_store_pkg(const package_info& pkg, const git_remote_listing& git)
sqlite3::exec( //
_stmt_cache,
R"(
INSERT INTO dds_repo_pkgs (
INSERT INTO dds_cat_pkgs (
name,
version,
git_url,
@@ -142,7 +143,7 @@ void catalog::store(const package_info& pkg) {

auto db_pkg_id = _db.last_insert_rowid();
auto& new_dep_st = _stmt_cache(R"(
INSERT INTO dds_repo_pkg_deps (
INSERT INTO dds_cat_pkg_deps (
pkg_id,
dep_name,
low,
@@ -169,7 +170,7 @@ std::vector<package_id> catalog::by_name(std::string_view sv) const noexcept {
_stmt_cache,
R"(
SELECT name, version
FROM dds_repo_pkgs
FROM dds_cat_pkgs
WHERE name = ?
)"_sql,
std::tie(sv)) //
@@ -187,11 +188,11 @@ std::vector<dependency> catalog::dependencies_of(const package_id& pkg) const no
R"(
WITH this_pkg_id AS (
SELECT pkg_id
FROM dds_repo_pkgs
FROM dds_cat_pkgs
WHERE name = ? AND version = ?
)
SELECT dep_name, low
FROM dds_repo_pkg_deps
FROM dds_cat_pkg_deps
WHERE pkg_id IN this_pkg_id
ORDER BY dep_name
)"_sql,

src/dds/repo/catalog.hpp → src/dds/catalog/catalog.hpp Dosyayı Görüntüle


src/dds/repo/catalog.test.cpp → src/dds/catalog/catalog.test.cpp Dosyayı Görüntüle

@@ -1,4 +1,4 @@
#include <dds/repo/catalog.hpp>
#include <dds/catalog/catalog.hpp>

#include <catch2/catch.hpp>


+ 96
- 7
src/dds/dds.main.cpp Dosyayı Görüntüle

@@ -1,4 +1,5 @@
#include <dds/build.hpp>
#include <dds/catalog/catalog.hpp>
#include <dds/repo/remote.hpp>
#include <dds/repo/repo.hpp>
#include <dds/sdist.hpp>
@@ -92,6 +93,89 @@ struct common_project_flags {
dds::fs::current_path()};
};

/*
###### ### ######## ### ## ####### ######
## ## ## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ####
## ######### ## ######### ## ## ## ## ##
## ## ## ## ## ## ## ## ## ## ## ##
###### ## ## ## ## ## ######## ####### ######
*/

struct cli_catalog {
cli_base& base;
args::Command cmd{base.cmd_group, "catalog", "Manage the package catalog"};
common_flags _common{cmd};

args::Group cat_group{cmd, "Catalog subcommands"};

struct catalog_path_flag : path_flag {
catalog_path_flag(args::Group& cmd)
: path_flag(cmd,
"catalog-path",
"Path to the catalog database",
{"catalog", 'c'},
args::Options::Required) {}
};

struct {
cli_catalog& parent;
args::Command cmd{parent.cat_group, "create", "Create a catalog database"};

catalog_path_flag path{cmd};

int run() {
// Simply opening the DB will initialize the catalog
dds::catalog::open(path.Get());
return 0;
}
} create{*this};

struct {
cli_catalog& parent;
args::Command cmd{parent.cat_group, "import", "Import json data into a catalog"};

catalog_path_flag path{cmd};
args::PositionalList<std::string> json_paths{cmd,
"json",
"Path to the JSON files to import"};

int run() {
auto cat = dds::catalog::open(path.Get());
for (const auto& json_fpath : json_paths.Get()) {
cat.import_json_file(json_fpath);
}
return 0;
}
} import{*this};

struct {
cli_catalog& parent;
args::Command cmd{parent.cat_group, "get", "Obtain an sdist from a catalog listing"};

catalog_path_flag path{cmd};
args::PositionalList<std::string> requirements{cmd,
"requirement",
"The package IDs to obtain"};

int run() { return 23; }
} get{*this};

int run() {
if (create.cmd) {
return create.run();
} else if (import.cmd) {
return import.run();
} else if (get.cmd) {
return get.run();
} else {
assert(false);
std::terminate();
}
}
};

/*
######## ######## ######## #######
## ## ## ## ## ## ##
@@ -118,8 +202,9 @@ struct cli_repo {

int run() {
auto list_contents = [&](dds::repository repo) {
auto same_name
= [](auto&& a, auto&& b) { return a.manifest.pk_id.name == b.manifest.pk_id.name; };
auto same_name = [](auto&& a, auto&& b) {
return a.manifest.pk_id.name == b.manifest.pk_id.name;
};

auto all = repo.iter_sdists();
auto grp_by_name = all //
@@ -290,6 +375,7 @@ struct cli_build {
args::Flag build_apps{cmd, "build_apps", "Build applications", {"apps", 'A'}};
args::Flag export_{cmd, "export", "Generate a library export", {"export", 'E'}};
toolchain_flag tc_filepath{cmd};

args::Flag enable_warnings{cmd,
"enable_warnings",
"Enable compiler warnings",
@@ -502,11 +588,12 @@ int main(int argc, char** argv) {
spdlog::set_pattern("[%H:%M:%S] [%^%-5l%$] %v");
args::ArgumentParser parser("DDS - The drop-dead-simple library manager");

cli_base cli{parser};
cli_build build{cli};
cli_sdist sdist{cli};
cli_repo repo{cli};
cli_deps deps{cli};
cli_base cli{parser};
cli_build build{cli};
cli_sdist sdist{cli};
cli_repo repo{cli};
cli_deps deps{cli};
cli_catalog catalog{cli};
try {
parser.ParseCLI(argc, argv);
} catch (const args::Help&) {
@@ -532,6 +619,8 @@ int main(int argc, char** argv) {
return repo.run();
} else if (deps.cmd) {
return deps.run();
} else if (catalog.cmd) {
return catalog.run();
} else {
assert(false);
std::terminate();

Yükleniyor…
İptal
Kaydet