瀏覽代碼

Remove old .dds parsing code, and update tests appropriately

default_compile_flags
vector-of-bool 4 年之前
父節點
當前提交
e0a4f6d732
共有 13 個檔案被更改,包括 38 行新增154 行删除
  1. +1
    -50
      src/dds/library/manifest.cpp
  2. +0
    -1
      src/dds/library/manifest.hpp
  3. +1
    -5
      src/dds/library/root.cpp
  4. +1
    -65
      src/dds/package/manifest.cpp
  5. +0
    -1
      src/dds/package/manifest.hpp
  6. +1
    -2
      src/dds/source/dist.cpp
  7. +10
    -7
      tests/basics/test_simple.py
  8. +5
    -6
      tests/catalog/get_test.py
  9. +6
    -2
      tests/deps/build-deps/project/catalog.json
  10. +1
    -1
      tests/deps/build-deps/project/deps.json5
  11. +5
    -5
      tests/deps/build-deps/test_build_deps.py
  12. +6
    -8
      tests/deps/git-remote/catalog.json
  13. +1
    -1
      tests/deps/git-remote/package.json5

+ 1
- 50
src/dds/library/manifest.cpp 查看文件

@@ -3,7 +3,6 @@
#include <dds/dym.hpp>
#include <dds/error/errors.hpp>
#include <dds/util/algo.hpp>
#include <libman/parse.hpp>

#include <json5/parse_data.hpp>
#include <range/v3/view/transform.hpp>
@@ -12,27 +11,6 @@

using namespace dds;

library_manifest library_manifest::load_from_dds_file(path_ref fpath) {
spdlog::warn(
"Using deprecated library.dds parsing (on file {}). This will be removed soon. Migrate!",
fpath.string());
auto kvs = lm::parse_file(fpath);
library_manifest ret;
ret.name = fpath.parent_path().filename().string();
std::vector<std::string> uses_strings;
std::vector<std::string> links_strings;
lm::read(fmt::format("Reading library manifest {}", fpath.string()),
kvs,
lm::read_accumulate("Uses", uses_strings),
lm::read_accumulate("Links", links_strings),
lm::read_required("Name", ret.name),
lm_reject_dym{{"Uses", "Links", "Name"}});

extend(ret.uses, ranges::views::transform(uses_strings, lm::split_usage_string));
extend(ret.links, ranges::views::transform(links_strings, lm::split_usage_string));
return ret;
}

library_manifest library_manifest::load_from_file(path_ref fpath) {
auto content = slurp_file(fpath);
auto data = json5::parse_data(content);
@@ -76,24 +54,6 @@ library_manifest library_manifest::load_from_file(path_ref fpath) {
if (rej) {
throw_user_error<errc::invalid_lib_manifest>(rej->message);
}
// using namespace json_read::ops;
// json_read::decompose( //
// data.as_object(),
// object(key("name", require_string(put_into{lib.name}, "`name` must be a string")),
// key("uses",
// array_each{require_string(
// [&](auto&& uses) {
// lib.uses.push_back(lm::split_usage_string(uses.as_string()));
// return json_read::accept_t{};
// },
// "All `uses` items must be strings")}),
// key("links",
// array_each{require_string(
// [&](auto&& links) {
// lib.links.push_back(lm::split_usage_string(links.as_string()));
// return json_read::accept_t{};
// },
// "All `links` items must be strings")})));

if (lib.name.empty()) {
throw_user_error<errc::invalid_lib_manifest>(
@@ -116,11 +76,6 @@ std::optional<fs::path> library_manifest::find_in_directory(path_ref dirpath) {
}
}

auto dds_file = dirpath / "library.dds";
if (fs::is_regular_file(dds_file)) {
return dds_file;
}

return std::nullopt;
}

@@ -130,9 +85,5 @@ std::optional<library_manifest> library_manifest::load_from_directory(path_ref d
return std::nullopt;
}

if (found->extension() == ".dds") {
return load_from_dds_file(*found);
} else {
return load_from_file(*found);
}
return load_from_file(*found);
}

+ 0
- 1
src/dds/library/manifest.hpp 查看文件

@@ -25,7 +25,6 @@ struct library_manifest {
* Load the library manifest from an existing file
*/
static library_manifest load_from_file(path_ref);
static library_manifest load_from_dds_file(path_ref);

/**
* Find a library manifest within a directory. This will search for a few

+ 1
- 5
src/dds/library/root.cpp 查看文件

@@ -59,11 +59,7 @@ library_root library_root::from_directory(path_ref lib_dir) {
man.name = lib_dir.filename().string();
auto found = library_manifest::find_in_directory(lib_dir);
if (found) {
if (found->extension() == ".dds") {
man = library_manifest::load_from_dds_file(*found);
} else {
man = library_manifest::load_from_file(*found);
}
man = library_manifest::load_from_file(*found);
}

auto lib = library_root(lib_dir, std::move(sources), std::move(man));

+ 1
- 65
src/dds/package/manifest.cpp 查看文件

@@ -3,7 +3,6 @@
#include <dds/dym.hpp>
#include <dds/error/errors.hpp>
#include <dds/util/string.hpp>
#include <libman/parse.hpp>

#include <range/v3/view/split.hpp>
#include <range/v3/view/split_when.hpp>
@@ -15,61 +14,6 @@

using namespace dds;

package_manifest package_manifest::load_from_dds_file(const fs::path& fpath) {
spdlog::warn(
"Using deprecated package.dds parsing (on file {}). This will be removed soon. Migrate!",
fpath.string());
auto kvs = lm::parse_file(fpath);
package_manifest ret;
std::string version_str;
std::vector<std::string> depends_strs;
std::optional<std::string> opt_test_driver;
lm::read(fmt::format("Reading package manifest '{}'", fpath.string()),
kvs,
lm::read_required("Name", ret.pkg_id.name),
lm::read_opt("Namespace", ret.namespace_),
lm::read_required("Version", version_str),
lm::read_accumulate("Depends", depends_strs),
lm::read_opt("Test-Driver", opt_test_driver),
lm_reject_dym{{"Name", "Namespace", "Version", "Depends", "Test-Driver"}});

if (ret.pkg_id.name.empty()) {
throw_user_error<errc::invalid_pkg_name>("'Name' field in [{}] may not be an empty string",
fpath.string());
}
if (version_str.empty()) {
throw_user_error<
errc::invalid_version_string>("'Version' field in [{}] may not be an empty string",
fpath.string());
}
if (opt_test_driver) {
auto& test_driver_str = *opt_test_driver;
if (test_driver_str == "Catch-Main") {
ret.test_driver = test_lib::catch_main;
} else if (test_driver_str == "Catch") {
ret.test_driver = test_lib::catch_;
} else {
auto dym = *did_you_mean(test_driver_str, {"Catch-Main", "Catch"});
throw_user_error<
errc::unknown_test_driver>("Unknown 'test_driver' '{}' (Did you mean '{}'?)",
test_driver_str,
dym);
}
}

if (ret.namespace_.empty()) {
ret.namespace_ = ret.pkg_id.name;
}

ret.pkg_id.version = semver::version::parse(version_str);

ret.dependencies = depends_strs //
| ranges::views::transform(dependency::parse_depends_string) //
| ranges::to_vector;

return ret;
}

package_manifest package_manifest::load_from_file(const fs::path& fpath) {
auto content = slurp_file(fpath);
auto data = json5::parse_data(content);
@@ -179,10 +123,6 @@ std::optional<fs::path> package_manifest::find_in_directory(path_ref dirpath) {
}
}

auto dds_fname = dirpath / "package.dds";
if (fs::is_regular_file(dds_fname)) {
return dds_fname;
}
return std::nullopt;
}

@@ -191,9 +131,5 @@ std::optional<package_manifest> package_manifest::load_from_directory(path_ref d
if (!found.has_value()) {
return std::nullopt;
}
if (found->extension() == ".dds") {
return load_from_dds_file(*found);
} else {
return load_from_file(*found);
}
return load_from_file(*found);
}

+ 0
- 1
src/dds/package/manifest.hpp 查看文件

@@ -35,7 +35,6 @@ struct package_manifest {
* Load a package manifest from a file on disk.
*/
static package_manifest load_from_file(path_ref);
static package_manifest load_from_dds_file(path_ref);

/**
* Find a package manifest contained within a directory. This will search

+ 1
- 2
src/dds/source/dist.cpp 查看文件

@@ -96,8 +96,7 @@ sdist dds::create_sdist_in_dir(path_ref out, const sdist_params& params) {
params.project_dir.string());
}

auto pkg_man = man_path->extension() == ".dds" ? package_manifest::load_from_dds_file(*man_path)
: package_manifest::load_from_file(*man_path);
auto pkg_man = package_manifest::load_from_file(*man_path);
sdist_export_file(out, params.project_dir, *man_path);
spdlog::info("Generated export as {}", pkg_man.pkg_id.to_string());
return sdist::from_directory(out);

+ 10
- 7
tests/basics/test_simple.py 查看文件

@@ -12,17 +12,20 @@ def test_simple_lib(dds: DDS, scope: ExitStack):

scope.enter_context(
dds.set_contents(
'library.dds',
b'Name: TestLibrary',
'library.json5',
b'''{
name: 'TestLibrary',
}''',
))

scope.enter_context(
dds.set_contents(
'package.dds',
b'''
Name: TestProject
Version: 0.0.0
''',
'package.json5',
b'''{
name: 'TestProject',
version: '0.0.0',
namespace: 'test',
}''',
))

dds.build(tests=True, apps=False, warnings=False)

+ 5
- 6
tests/catalog/get_test.py 查看文件

@@ -15,13 +15,12 @@ def test_get(dds: DDS):
'version': 1,
'packages': {
'neo-sqlite3': {
'0.2.2': {
'depends': {},
'0.3.0': {
'git': {
'url':
'https://github.com/vector-of-bool/neo-sqlite3.git',
'ref':
'0.2.2',
'0.3.0',
},
},
},
@@ -33,6 +32,6 @@ def test_get(dds: DDS):

dds.catalog_import(json_path)

dds.catalog_get('neo-sqlite3@0.2.2')
assert (dds.source_root / 'neo-sqlite3@0.2.2').is_dir()
assert (dds.source_root / 'neo-sqlite3@0.2.2/package.dds').is_file()
dds.catalog_get('neo-sqlite3@0.3.0')
assert (dds.source_root / 'neo-sqlite3@0.3.0').is_dir()
assert (dds.source_root / 'neo-sqlite3@0.3.0/package.jsonc').is_file()

+ 6
- 2
tests/deps/build-deps/project/catalog.json 查看文件

@@ -7,14 +7,18 @@
"url": "https://github.com/vector-of-bool/neo-sqlite3.git",
"ref": "0.1.0"
},
"depends": {}
},
"0.2.2": {
"git": {
"url": "https://github.com/vector-of-bool/neo-sqlite3.git",
"ref": "0.2.2"
},
"depends": {}
},
"0.3.0": {
"git": {
"url": "https://github.com/vector-of-bool/neo-sqlite3.git",
"ref": "0.3.0"
},
}
}
}

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

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

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

@@ -5,7 +5,7 @@ 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.json5'])
assert (dds.deps_build_dir / 'neo-sqlite3@0.2.2').is_dir()
assert (dds.deps_build_dir / 'neo-sqlite3@0.3.0').is_dir()
assert (dds.scratch_dir / 'INDEX.lmi').is_file()
assert (dds.deps_build_dir / '_libman/neo-sqlite3.lmp').is_file()
assert (dds.deps_build_dir / '_libman/neo/sqlite3.lml').is_file()
@@ -14,8 +14,8 @@ def test_build_deps_from_file(dds: DDS):
def test_build_deps_from_cmd(dds: DDS):
assert not dds.deps_build_dir.is_dir()
dds.catalog_import(dds.source_root / 'catalog.json')
dds.build_deps(['neo-sqlite3=0.2.2'])
assert (dds.deps_build_dir / 'neo-sqlite3@0.2.2').is_dir()
dds.build_deps(['neo-sqlite3=0.3.0'])
assert (dds.deps_build_dir / 'neo-sqlite3@0.3.0').is_dir()
assert (dds.scratch_dir / 'INDEX.lmi').is_file()
assert (dds.deps_build_dir / '_libman/neo-sqlite3.lmp').is_file()
assert (dds.deps_build_dir / '_libman/neo/sqlite3.lml').is_file()
@@ -24,8 +24,8 @@ def test_build_deps_from_cmd(dds: DDS):
def test_multiple_deps(dds: DDS):
assert not dds.deps_build_dir.is_dir()
dds.catalog_import(dds.source_root / 'catalog.json')
dds.build_deps(['neo-sqlite3^0.2.2', 'neo-sqlite3~0.2.0'])
assert (dds.deps_build_dir / 'neo-sqlite3@0.2.2').is_dir()
dds.build_deps(['neo-sqlite3^0.2.0', 'neo-sqlite3~0.3.0'])
assert (dds.deps_build_dir / 'neo-sqlite3@0.3.0').is_dir()
assert (dds.scratch_dir / 'INDEX.lmi').is_file()
assert (dds.deps_build_dir / '_libman/neo-sqlite3.lmp').is_file()
assert (dds.deps_build_dir / '_libman/neo/sqlite3.lml').is_file()

+ 6
- 8
tests/deps/git-remote/catalog.json 查看文件

@@ -1,13 +1,12 @@
{
"version": 1,
"packages": {
"neo-buffer": {
"0.1.0": {
"neo-fun": {
"0.3.2": {
"git": {
"url": "https://github.com/vector-of-bool/neo-buffer.git",
"ref": "0.1.0"
},
"depends": {}
"url": "https://github.com/vector-of-bool/neo-fun.git",
"ref": "0.3.2"
}
}
},
"range-v3": {
@@ -16,8 +15,7 @@
"url": "https://github.com/ericniebler/range-v3.git",
"ref": "0.9.1",
"auto-lib": "Niebler/range-v3"
},
"depends": {}
}
}
}
}

+ 1
- 1
tests/deps/git-remote/package.json5 查看文件

@@ -3,7 +3,7 @@
"namespace": "test",
version: '0.0.0',
depends: {
'neo-buffer': '0.1.0',
'neo-fun': '0.3.2',
'range-v3': '0.9.1',
}
}

Loading…
取消
儲存