This commit is contained in:
Your Name 2025-05-17 09:36:55 +12:00
parent 7cdb08746e
commit 465d0daa9c
3 changed files with 14 additions and 12 deletions

Binary file not shown.

View File

@ -70,7 +70,7 @@ static uint64_t fnv1a_64(const void* data, size_t len) {
// Reset to decimal format
cpp << std::dec;
cpp << "static const size_t filedata_len = " << filedata.size() << ";\n";
cpp << "static const char* file_hash = \"" << hash << "\";\n";
cpp << "static uint64_t file_hash = " << hash << "U;\n";
cpp << R"cpp(
bool recreate_file(std::string destination_folder) {
namespace fs = std::filesystem;
@ -88,13 +88,11 @@ bool recreate_file(std::string destination_folder) {
std::ofstream out(outpath, std::ios::binary);
out.write(reinterpret_cast<const char*>(filedata), filedata_len);
}
std::cout << "[dehydrate] " << outpath << ": ";
if (!fs::exists(outpath)) {
std::cout << "created\n";
std::cout << "[dehydrate] " << outpath.filename() << ": created\n";
} else if (needs_write) {
std::cout << "updated (hash changed)\n";
} else {
std::cout << "unchanged (hash match)\n";
std::cout << "[dehydrate] " << outpath.filename() << ": updated (hash changed)\n";
}
return needs_write;
}
@ -202,7 +200,7 @@ static uint64_t fnv1a_64(const void* data, size_t len) {
// Reset to decimal format
cpp << std::dec;
cpp << "static const size_t len_" << var << " = " << filedata.size() << ";\n";
cpp << "static uint64_t hash_" << var << " = \"" << hash << "\";\n";
cpp << "static uint64_t hash_" << var << " = " << hash << "U;\n";
cpp << "static const char* rel_" << var << " = \"" << rel << "\";\n";
}
// Write recreate_tree using heredoc style
@ -229,13 +227,11 @@ bool recreate_tree(std::string destination_folder) {
std::ofstream out(outpath, std::ios::binary);
out.write(reinterpret_cast<const char*>()cpp" << "data_" << var << R"cpp(), )cpp" << "len_" << var << R"cpp();
}
std::cout << "[dehydrate] " << outpath << ": ";
if (!fs::exists(outpath)) {
std::cout << "created\n";
std::cout << "[dehydrate] " << outpath.filename() << ": created\n";
} else if (needs_write) {
std::cout << "updated (hash changed)\n";
} else {
std::cout << "unchanged (hash match)\n";
std::cout << "[dehydrate] " << outpath.filename() << ": updated (hash changed)\n";
}
any_written = any_written || needs_write;
}

View File

@ -28,13 +28,19 @@ EOF
g++ -std=c++17 -I $TEST_DIR -o $TEST_DIR/testexe $TEST_DIR/main.cpp $TEST_DIR/_src.cpp
echo "----------------------------------------"
echo "Should generate all files from src/"
$TEST_DIR/testexe
# second time should be no changes (hash should match)
echo "----------------------------------------"
echo "Should be no changes - rerun on same output"
$TEST_DIR/testexe
# third time just two files changed
echo "----------------------------------------"
echo "Should be two changes: generator.cpp and hash.cpp"
rm $TEST_DIR/temp/generator.cpp
echo "whee!" >> $TEST_DIR/temp/hash.cpp