Bläddra i källkod

Automatic package generation from unchanged Git remotes

default_compile_flags
vector-of-bool 5 år sedan
förälder
incheckning
8546a5722a
6 ändrade filer med 76 tillägg och 31 borttagningar
  1. +20
    -8
      src/dds/repo/remote.cpp
  2. +4
    -2
      src/dds/repo/remote.hpp
  3. +2
    -13
      src/libman/library.cpp
  4. +47
    -7
      src/libman/parse.hpp
  5. +1
    -0
      tests/deps/git-remote/package.dds
  6. +2
    -1
      tests/deps/git-remote/remote.dds

+ 20
- 8
src/dds/repo/remote.cpp Visa fil

@@ -43,18 +43,20 @@ struct read_listing_item {
semver::version version,
const lm::pair_list& pairs) {
if (pairs.find("git")) {
std::string url;
std::string ref;
std::string url;
std::string ref;
std::optional<lm::usage> auto_id;
lm::read(fmt::format("{}: Parsing Git remote listing", context),
pairs,
lm::read_required("url", url),
lm::read_required("ref", ref),
lm::read_check_eq("git", ""),
lm::read_opt("auto", auto_id, &lm::split_usage_string),
lm::reject_unknown());
auto did_insert
= out.emplace(
remote_listing{std::move(name), version, git_remote_listing{url, ref}})
.second;
auto did_insert = out.emplace(remote_listing{std::move(name),
version,
git_remote_listing{url, ref, auto_id}})
.second;
if (!did_insert) {
spdlog::warn("Duplicate remote package defintion for {} {}",
name,
@@ -68,7 +70,7 @@ struct read_listing_item {
}
};

temporary_sdist do_pull_sdist(const git_remote_listing& git) {
temporary_sdist do_pull_sdist(const remote_listing& listing, const git_remote_listing& git) {
auto tmpdir = dds::temporary_dir::create();
using namespace std::literals;
spdlog::info("Cloning repository: {} [{}] ...", git.url, git.ref);
@@ -88,6 +90,16 @@ temporary_sdist do_pull_sdist(const git_remote_listing& git) {
git_res.output));
}
spdlog::info("Create sdist from clone ...");
if (git.auto_lib.has_value()) {
spdlog::info("Generating library data automatically");
auto pkg_strm = dds::open(tmpdir.path() / "package.dds", std::ios::binary | std::ios::out);
pkg_strm << "Name: " << listing.name << '\n' //
<< "Version: " << listing.version.to_string() << '\n' //
<< "Namespace: " << git.auto_lib->namespace_;
auto lib_strm = dds::open(tmpdir.path() / "library.dds", std::ios::binary | std::ios::out);
lib_strm << "Name: " << git.auto_lib->name;
}

sdist_params params;
params.project_dir = tmpdir.path();
auto sd_tmp_dir = dds::temporary_dir::create();
@@ -100,7 +112,7 @@ temporary_sdist do_pull_sdist(const git_remote_listing& git) {
} // namespace

temporary_sdist remote_listing::pull_sdist() const {
auto tsd = visit([](auto&& actual) { return do_pull_sdist(actual); });
auto tsd = visit([&](auto&& actual) { return do_pull_sdist(*this, actual); });
if (tsd.sdist.manifest.name != name) {
throw std::runtime_error(
fmt::format("The name in the generated sdist ('{}') does not match the name listed in "

+ 4
- 2
src/dds/repo/remote.hpp Visa fil

@@ -5,6 +5,7 @@
#include <dds/sdist.hpp>
#include <dds/temp.hpp>
#include <semver/version.hpp>
#include <libman/library.hpp>

#include <set>
#include <string>
@@ -20,8 +21,9 @@ struct temporary_sdist {
};

struct git_remote_listing {
std::string url;
std::string ref;
std::string url;
std::string ref;
std::optional<lm::usage> auto_lib;

void clone(path_ref path) const;
};

+ 2
- 13
src/libman/library.cpp Visa fil

@@ -11,9 +11,6 @@ library library::from_file(path_ref fpath) {

library ret;

std::vector<std::string> uses_strs;
std::vector<std::string> links_strs;

std::string _type_;
read(fmt::format("Reading library manifest file '{}'", fpath.string()),
pairs,
@@ -23,18 +20,10 @@ library library::from_file(path_ref fpath) {
read_opt("Path", ret.linkable_path),
read_accumulate("Include-Path", ret.include_paths),
read_accumulate("Preprocessor-Define", ret.preproc_defs),
read_accumulate("Uses", uses_strs),
read_accumulate("Links", links_strs),
read_accumulate("Uses", ret.uses, &split_usage_string),
read_accumulate("Links", ret.links, &split_usage_string),
read_accumulate("Special-Uses", ret.special_uses));

for (auto&& uses_str : uses_strs) {
ret.uses.push_back(split_usage_string(uses_str));
}

for (auto&& links_str : links_strs) {
ret.links.push_back(split_usage_string(links_str));
}

auto make_absolute = [&](path_ref p) { return fpath.parent_path() / p; };
std::transform(ret.include_paths.begin(),
ret.include_paths.end(),

+ 47
- 7
src/libman/parse.hpp Visa fil

@@ -120,6 +120,13 @@ struct nested_kvlist {
static nested_kvlist parse(std::string_view s);
};

struct unchanged {
template <typename Item>
auto operator()(Item&& item) const {
return item;
}
};

template <typename What>
class read_required {
std::string_view _key;
@@ -152,16 +159,18 @@ public:
}
};

template <typename T>
template <typename T, typename Transform = unchanged>
class read_opt {
std::string_view _key;
T& _ref;
bool _did_read = false;
Transform _tr;

public:
read_opt(std::string_view key, T& ref)
read_opt(std::string_view key, T& ref, Transform tr = unchanged())
: _key(key)
, _ref(ref) {}
, _ref(ref)
, _tr(std::move(tr)) {}

int operator()(std::string_view context, std::string_view key, std::string_view value) {
if (key != _key) {
@@ -171,7 +180,7 @@ public:
throw std::runtime_error(std::string(context) + ": Duplicated key '" + std::string(key)
+ "' is not allowed.");
}
_ref = T(value);
_ref = T(_tr(value));
return 1;
}
};
@@ -209,6 +218,30 @@ public:
}
};

struct read_empty_set_true {
std::string_view _key;
bool& _bool;
bool _seen = false;

bool operator()(std::string_view context, std::string_view key, std::string_view value) {
if (key != _key) {
return false;
}
if (value != "") {
throw std::runtime_error(std::string(context) + ": Key '" + std::string(key)
+ "' does not expected a value (Got '" + std::string(value)
+ "').");
}
if (_seen) {
throw std::runtime_error(std::string(context) + ": Duplicated key '" + std::string(key)
+ "'");
}
_bool = true;
_seen = true;
return true;
}
};

class read_check_eq {
std::string_view _key;
std::string_view _expect;
@@ -231,19 +264,26 @@ public:
}
};

template <typename Container>
template <typename Container, typename Transform = unchanged>
class read_accumulate {
std::string_view _key;
Container& _items;
Transform _tr;

public:
read_accumulate(std::string_view key, Container& c, Transform tr)
: _key(key)
, _items(c)
, _tr(std::move(tr)) {}

read_accumulate(std::string_view key, Container& c)
: _key(key)
, _items(c) {}
, _items(c)
, _tr(unchanged()) {}

int operator()(std::string_view, std::string_view key, std::string_view value) const {
if (key == _key) {
_items.emplace_back(value);
_items.emplace_back(_tr(value));
return 1;
}
return 0;

+ 1
- 0
tests/deps/git-remote/package.dds Visa fil

@@ -2,3 +2,4 @@ Name: deps-test
Version: 0.0.0

Depends: neo-buffer 0.1.0
Depends: range-v3 0.9.1

+ 2
- 1
tests/deps/git-remote/remote.dds Visa fil

@@ -1 +1,2 @@
Remote-Package: neo-buffer 0.1.0; git url=https://github.com/vector-of-bool/neo-buffer.git ref=develop
Remote-Package: neo-buffer 0.1.0; git url=https://github.com/vector-of-bool/neo-buffer.git ref=develop
Remote-Package: range-v3 0.9.1; git url=https://github.com/ericniebler/range-v3.git ref=0.9.1 auto=Niebler/range-v3

Laddar…
Avbryt
Spara