Browse Source

Use package_id in remote package listings

default_compile_flags
vector-of-bool 5 years ago
parent
commit
409dc2c83e
5 changed files with 26 additions and 46 deletions
  1. +16
    -36
      src/dds/repo/remote.cpp
  2. +6
    -6
      src/dds/repo/remote.hpp
  3. +2
    -2
      tests/deps/git-remote/remote.dds
  4. +1
    -1
      tests/deps/use-remote/remote.dds
  5. +1
    -1
      tests/deps/use-spdlog/project/remote.dds

+ 16
- 36
src/dds/repo/remote.cpp View File

return false; return false;
} }


auto nested = lm::nested_kvlist::parse(value);
auto name_ver_pair = split_shell_string(nested.primary);
if (name_ver_pair.size() != 2) {
throw std::runtime_error(
fmt::format("{}: Invalid Remote-Package identity: '{}'", context, nested.primary));
}
auto name = name_ver_pair[0];
auto version = semver::version::parse(name_ver_pair[1]);
put_listing(context, name, version, nested.pairs);
auto nested = lm::nested_kvlist::parse(value);
auto pk_id = package_id::parse(nested.primary);
put_listing(context, std::move(pk_id), nested.pairs);
return true; return true;
} }


void put_listing(std::string_view context,
std::string name,
semver::version version,
const lm::pair_list& pairs) {
void put_listing(std::string_view context, package_id pk_id, const lm::pair_list& pairs) {
if (pairs.find("git")) { if (pairs.find("git")) {
std::string url; std::string url;
std::string ref; std::string ref;
lm::read_check_eq("git", ""), lm::read_check_eq("git", ""),
lm::read_opt("auto", auto_id, &lm::split_usage_string), lm::read_opt("auto", auto_id, &lm::split_usage_string),
lm::reject_unknown()); lm::reject_unknown());
auto did_insert = out.emplace(remote_listing{std::move(name),
version,
auto did_insert = out.emplace(remote_listing{std::move(pk_id),
git_remote_listing{url, ref, auto_id}}) git_remote_listing{url, ref, auto_id}})
.second; .second;
if (!did_insert) { if (!did_insert) {
spdlog::warn("Duplicate remote package defintion for {} {}",
name,
version.to_string());
spdlog::warn("Duplicate remote package defintion for {}", pk_id.to_string());
} }
} else { } else {
throw std::runtime_error(fmt::format("Unable to determine remote type of package {} {}",
name,
version.to_string()));
throw std::runtime_error(
fmt::format("Unable to determine remote type of package {}", pk_id.to_string()));
} }
} }
}; };
if (git.auto_lib.has_value()) { if (git.auto_lib.has_value()) {
spdlog::info("Generating library data automatically"); spdlog::info("Generating library data automatically");
auto pkg_strm = dds::open(tmpdir.path() / "package.dds", std::ios::binary | std::ios::out); 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' //
pkg_strm << "Name: " << listing.pk_id.name << '\n' //
<< "Version: " << listing.pk_id.version.to_string() << '\n' //
<< "Namespace: " << git.auto_lib->namespace_; << "Namespace: " << git.auto_lib->namespace_;
auto lib_strm = dds::open(tmpdir.path() / "library.dds", std::ios::binary | std::ios::out); auto lib_strm = dds::open(tmpdir.path() / "library.dds", std::ios::binary | std::ios::out);
lib_strm << "Name: " << git.auto_lib->name; lib_strm << "Name: " << git.auto_lib->name;


temporary_sdist remote_listing::pull_sdist() const { temporary_sdist remote_listing::pull_sdist() const {
auto tsd = visit([&](auto&& actual) { return do_pull_sdist(*this, actual); }); auto tsd = visit([&](auto&& actual) { return do_pull_sdist(*this, actual); });
if (tsd.sdist.manifest.pk_id.name != name) {
throw std::runtime_error(
fmt::format("The name in the generated sdist ('{}') does not match the name listed in "
"the remote listing file (expected '{}')",
tsd.sdist.manifest.pk_id.name,
name));
}
if (tsd.sdist.manifest.pk_id.version != version) {
throw std::runtime_error(
fmt::format("The version of the generated sdist is '{}', which does not match the "
"expected version '{}'",
tsd.sdist.manifest.pk_id.version.to_string(),
version.to_string()));
if (!(tsd.sdist.manifest.pk_id == pk_id)) {
throw std::runtime_error(fmt::format(
"The package name@version in the generated sdist does not match the name listed in "
"the remote listing file (expected '{}', but got '{}')",
pk_id.to_string(),
tsd.sdist.manifest.pk_id.to_string()));
} }
return tsd; return tsd;
} }

+ 6
- 6
src/dds/repo/remote.hpp View File

}; };


struct remote_listing { struct remote_listing {
std::string name;
semver::version version;
package_id pk_id;
std::variant<git_remote_listing> remote; std::variant<git_remote_listing> remote;


template <typename Func> template <typename Func>


inline constexpr struct remote_listing_compare_t { inline constexpr struct remote_listing_compare_t {
using is_transparent = int; using is_transparent = int;
auto tie(const remote_listing& rl) const { return std::tie(rl.name, rl.version); }
bool operator()(const remote_listing& lhs, const remote_listing& rhs) const { bool operator()(const remote_listing& lhs, const remote_listing& rhs) const {
return tie(lhs) < tie(rhs);
return lhs.pk_id < rhs.pk_id;
} }
template <typename Name, typename Version> template <typename Name, typename Version>
bool operator()(const remote_listing& lhs, const std::tuple<Name, Version>& rhs) const { bool operator()(const remote_listing& lhs, const std::tuple<Name, Version>& rhs) const {
return tie(lhs) < rhs;
auto&& [name, ver] = rhs;
return lhs.pk_id < package_id{name, ver};
} }
template <typename Name, typename Version> template <typename Name, typename Version>
bool operator()(const std::tuple<Name, Version>& lhs, const remote_listing& rhs) const { bool operator()(const std::tuple<Name, Version>& lhs, const remote_listing& rhs) const {
return lhs < tie(rhs);
auto&& [name, ver] = lhs;
return package_id{name, ver} < rhs.pk_id;
} }
} remote_listing_compare; } remote_listing_compare;



+ 2
- 2
tests/deps/git-remote/remote.dds View File

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
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

+ 1
- 1
tests/deps/use-remote/remote.dds View File

Remote-Package: nlohmann-json 3.7.1; git url=https://github.com/vector-of-bool/json.git ref=dds/3.7.1
Remote-Package: nlohmann-json@3.7.1; git url=https://github.com/vector-of-bool/json.git ref=dds/3.7.1

+ 1
- 1
tests/deps/use-spdlog/project/remote.dds View File

Remote-Package: spdlog 1.4.2; git url=https://github.com/gabime/spdlog.git ref=v1.4.2 auto=spdlog/spdlog
Remote-Package: spdlog@1.4.2; git url=https://github.com/gabime/spdlog.git ref=v1.4.2 auto=spdlog/spdlog

Loading…
Cancel
Save