diff --git a/build_arm64/dehydrate b/build_arm64/dehydrate index 4a3e46c..cb52951 100755 Binary files a/build_arm64/dehydrate and b/build_arm64/dehydrate differ diff --git a/src/generator.cpp b/src/generator.cpp index 59a9051..15c4014 100644 --- a/src/generator.cpp +++ b/src/generator.cpp @@ -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(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()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; } diff --git a/test.sh b/test.sh index fe64865..6e92f0e 100755 --- a/test.sh +++ b/test.sh @@ -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