瀏覽代碼

`build-deps` now uses json5 as well

default_compile_flags
vector-of-bool 4 年之前
父節點
當前提交
c09558eb8d
共有 4 個檔案被更改,包括 56 行新增29 行删除
  1. +50
    -26
      src/dds/deps.cpp
  2. +0
    -2
      tests/deps/build-deps/project/deps.dds
  3. +5
    -0
      tests/deps/build-deps/project/deps.json5
  4. +1
    -1
      tests/deps/build-deps/test_build_deps.py

+ 50
- 26
src/dds/deps.cpp 查看文件

@@ -1,22 +1,14 @@
#include "./deps.hpp"

#include <dds/dym.hpp>
#include <dds/error/errors.hpp>
#include <dds/repo/repo.hpp>
#include <dds/source/dist.hpp>
#include <dds/usage_reqs.hpp>
#include <dds/util/string.hpp>
#include <libman/index.hpp>
#include <libman/parse.hpp>

#include <range/v3/range/conversion.hpp>
#include <range/v3/view/transform.hpp>
#include <spdlog/spdlog.h>
#include <json5/parse_data.hpp>
#include <semester/decomp.hpp>

#include <spdlog/fmt/fmt.h>

#include <cctype>
#include <map>
#include <set>
#include <sstream>

using namespace dds;

@@ -42,20 +34,52 @@ dependency dependency::parse_depends_string(std::string_view str) {
}

dependency_manifest dependency_manifest::from_file(path_ref fpath) {
auto kvs = lm::parse_file(fpath);
dependency_manifest ret;
lm::read(
fmt::format("Reading dependencies from '{}'", fpath.string()),
kvs,
[&](auto, auto key, auto val) {
if (key == "Depends") {
ret.dependencies.push_back(dependency::parse_depends_string(val));
return true;
}
return false;
},
lm_reject_dym{{"Depends"}});
return ret;
auto content = slurp_file(fpath);
auto data = json5::parse_data(content);

dependency_manifest depman;
using namespace semester::decompose_ops;
auto res = semester::decompose(
data,
try_seq{
require_type<json5::data::mapping_type>{
"The root of a dependency manifest must be an object (mapping)"},
mapping{
if_key{"$schema", just_accept},
if_key{"depends",
require_type<json5::data::mapping_type>{
"`depends` must be a mapping between package names and version ranges"},
mapping{[&](auto pkg_name, const json5::data& range_str_) {
if (!range_str_.is_string()) {
throw_user_error<errc::invalid_pkg_manifest>(
"Issue in dependency manifest: Dependency for '{}' must be a "
"range string",
pkg_name);
}
try {
auto rng = semver::range::parse_restricted(range_str_.as_string());
dependency dep{std::string(pkg_name), {rng.low(), rng.high()}};
depman.dependencies.push_back(std::move(dep));
} catch (const semver::invalid_range&) {
throw_user_error<errc::invalid_version_range_string>(
"Invalid version range string '{}' in dependency declaration "
"for '{}'",
range_str_.as_string(),
pkg_name);
}
return semester::dc_accept;
}}},
[&](auto key, auto&&) {
return semester::dc_reject_t{
fmt::format("Unknown key `{}` in dependency manifest", key)};
}},
});
auto rej = std::get_if<semester::dc_reject_t>(&res);
if (rej) {
throw_user_error<errc::invalid_pkg_manifest>(rej->message);
}

return depman;
}

namespace {

+ 0
- 2
tests/deps/build-deps/project/deps.dds 查看文件

@@ -1,2 +0,0 @@

Depends: neo-sqlite3 +0.2.2

+ 5
- 0
tests/deps/build-deps/project/deps.json5 查看文件

@@ -0,0 +1,5 @@
{
depends: {
'neo-sqlite3': '+0.2.2',
},
}

+ 1
- 1
tests/deps/build-deps/test_build_deps.py 查看文件

@@ -4,7 +4,7 @@ from tests import dds, DDS
def test_build_deps_from_file(dds: DDS):
assert not dds.deps_build_dir.is_dir()
dds.catalog_import(dds.source_root / 'catalog.json')
dds.build_deps(['-d', 'deps.dds'])
dds.build_deps(['-d', 'deps.json5'])
assert (dds.deps_build_dir / 'neo-sqlite3@0.2.2').is_dir()
assert (dds.scratch_dir / 'INDEX.lmi').is_file()
assert (dds.deps_build_dir / '_libman/neo-sqlite3.lmp').is_file()

Loading…
取消
儲存