Procházet zdrojové kódy

Drop sdist hashing. We'll come back to that someday, but YAGNI for now

default_compile_flags
vector-of-bool před 5 roky
rodič
revize
1c0044d482
3 změnil soubory, kde provedl 13 přidání a 56 odebrání
  1. +2
    -3
      src/dds/dds.main.cpp
  2. +9
    -44
      src/dds/sdist.cpp
  3. +2
    -9
      src/dds/sdist.hpp

+ 2
- 3
src/dds/dds.main.cpp Zobrazit soubor

@@ -132,9 +132,8 @@ struct cli_repo {
for (const auto& [name, grp] : grp_by_name) {
spdlog::info("{}:", name);
for (const dds::sdist& sd : grp) {
spdlog::info(" - {} [{}]",
sd.manifest.version.to_string(),
sd.md5_string());
spdlog::info(" - {}",
sd.manifest.version.to_string());
}
}


+ 9
- 44
src/dds/sdist.cpp Zobrazit soubor

@@ -5,10 +5,6 @@

#include <libman/parse.hpp>

#include <browns/md5.hpp>
#include <browns/output.hpp>
#include <neo/buffer.hpp>

#include <range/v3/algorithm/sort.hpp>
#include <range/v3/view/filter.hpp>

@@ -18,30 +14,15 @@ using namespace dds;

namespace {

void hash_file(std::string_view prefix, path_ref fpath, browns::md5& hash) {
hash.feed(neo::buffer(prefix));
std::ifstream infile;
infile.exceptions(std::ios::failbit | std::ios::badbit);
using file_iter = std::istreambuf_iterator<char>;
infile.open(fpath, std::ios::binary);
assert(infile.good());
hash.feed(neo::buffer("\nfile_content: "));
hash.feed(file_iter(infile), file_iter());
}

void sdist_export_file(path_ref out_root, path_ref in_root, path_ref filepath, browns::md5& hash) {
void sdist_export_file(path_ref out_root, path_ref in_root, path_ref filepath) {
auto relpath = fs::relative(filepath, in_root);
spdlog::info("Export file {}", relpath.string());
hash_file("filepath:" + relpath.generic_string(), filepath, hash);
auto dest = out_root / relpath;
fs::create_directories(dest.parent_path());
fs::copy(filepath, dest);
}

void sdist_copy_library(path_ref out_root,
const library& lib,
const sdist_params& params,
browns::md5& hash) {
void sdist_copy_library(path_ref out_root, const library& lib, const sdist_params& params) {
auto sources_to_keep = //
lib.all_sources() //
| ranges::views::filter([&](const source_file& sf) {
@@ -66,12 +47,12 @@ void sdist_copy_library(path_ref out_root,
"Each library in a source distribution requires a library manifest (Expected [{}])",
lib_dds_path.string()));
}
sdist_export_file(out_root, params.project_dir, lib_dds_path, hash);
sdist_export_file(out_root, params.project_dir, lib_dds_path);

spdlog::info("sdist: Export library from {}", lib.path().string());
fs::create_directories(out_root);
for (const auto& source : sources_to_keep) {
sdist_export_file(out_root, params.project_dir, source.path, hash);
sdist_export_file(out_root, params.project_dir, source.path);
}
}

@@ -100,10 +81,8 @@ sdist dds::create_sdist(const sdist_params& params) {
sdist dds::create_sdist_in_dir(path_ref out, const sdist_params& params) {
auto libs = collect_libraries(params.project_dir);

browns::md5 md5;

for (const library& lib : libs) {
sdist_copy_library(out, lib, params, md5);
sdist_copy_library(out, lib, params);
}

auto man_path = params.project_dir / "package.dds";
@@ -111,29 +90,15 @@ sdist dds::create_sdist_in_dir(path_ref out, const sdist_params& params) {
throw std::runtime_error(fmt::format(
"Creating a source distribution requires a package.dds file for the project"));
}
sdist_export_file(out, params.project_dir, man_path, md5);
sdist_export_file(out, params.project_dir, man_path);
auto pkg_man = package_manifest::load_from_file(man_path);

md5.pad();
auto hash_str = browns::format_digest(md5.digest());
spdlog::info("Generated export as {}-{}", pkg_man.name, hash_str);

std::vector<lm::pair> pairs;
pairs.emplace_back("MD5-Hash", hash_str);
lm::write_pairs(out / "_sdist.dds", pairs);
spdlog::info("Generated export as {}_{}", pkg_man.name, pkg_man.version.to_string());

return sdist::from_directory(out);
}

sdist sdist::from_directory(path_ref where) {
auto pkg_man = package_manifest::load_from_file(where / "package.dds");
auto meta_pairs = lm::parse_file(where / "_sdist.dds");
std::string hash_str;
lm::read(fmt::format("Loading source distribution manifest from {}/_sdist.dds", where.string()),
meta_pairs,
lm::read_required("MD5-Hash", hash_str),
lm::reject_unknown());
return sdist{std::move(pkg_man),
browns::parse_digest<browns::md5::digest_type>(hash_str),
where};
auto pkg_man = package_manifest::load_from_file(where / "package.dds");
return sdist{std::move(pkg_man), where};
}

+ 2
- 9
src/dds/sdist.hpp Zobrazit soubor

@@ -3,9 +3,6 @@
#include <dds/package_manifest.hpp>
#include <dds/util/fs.hpp>

#include <browns/md5.hpp>
#include <browns/output.hpp>

namespace dds {

struct sdist_params {
@@ -18,20 +15,16 @@ struct sdist_params {

struct sdist {
package_manifest manifest;
browns::md5::digest_type md5;
fs::path path;

sdist(package_manifest man, browns::md5::digest_type hash, path_ref path_)
sdist(package_manifest man, path_ref path_)
: manifest(std::move(man))
, md5(hash)
, path(path_) {}

static sdist from_directory(path_ref p);

std::string md5_string() const noexcept { return browns::format_digest(md5); }

std::string ident() const noexcept {
return manifest.name + "." + manifest.version.to_string() + "." + md5_string();
return manifest.name + "_" + manifest.version.to_string();
}
};


Načítá se…
Zrušit
Uložit