diff --git a/.gitignore b/.gitignore index c268c65..3ac3b64 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,9 @@ # Output binaries and folders /output/ +# test folder +/test/ + # CMake files CMakeFiles/ CMakeCache.txt @@ -26,4 +29,4 @@ Makefile *.out # Generated recreator files (optional, if you want to ignore them) -_*.[ch]pp \ No newline at end of file +_*.[ch]pp diff --git a/build_arm64/dehydrate b/build_arm64/dehydrate index a10e4b3..4a3e46c 100755 Binary files a/build_arm64/dehydrate and b/build_arm64/dehydrate differ diff --git a/src/generator.cpp b/src/generator.cpp index db5088f..40d6676 100644 --- a/src/generator.cpp +++ b/src/generator.cpp @@ -118,7 +118,28 @@ void generate_folder_code(const std::string& source, const std::string& destfold walk_dir(src, [&](const fs::path& p) { files.push_back(p); }); // Write HPP std::ofstream hpp(dest / hppname); - hpp << "#pragma once\n#include \nnamespace " << ns << " {\nbool recreate_tree(std::string destination_folder);\n}\n"; + + // ------------------------------------------------------------------------- + // Generate HPP + hpp << R"hpp( +#pragma once + +/* + + THIS FILE IS AUTO-GENERATED BY DEHYDRATE. + DO NOT EDIT THIS FILE. + +*/ + + +#include +namespace )hpp" << ns << R"hpp( { + bool recreate_tree(std::string destination_folder); +} +)hpp"; + + + // ------------------------------------------------------------------------- // Write CPP std::ofstream cpp(dest / cppname); cpp << R"cpp(#include @@ -126,9 +147,34 @@ void generate_folder_code(const std::string& source, const std::string& destfold #include #include #include + + + +/* + + THIS FILE IS AUTO-GENERATED BY DEHYDRATE. + DO NOT EDIT THIS FILE. + +*/ + + )cpp"; cpp << "#include \"" << hppname << "\"\n"; cpp << "namespace " << ns << " {\n"; + + cpp << R"cpp( + +// Tiny dependency-free FNV-1a 64-bit hash +static uint64_t fnv1a_64(const void* data, size_t len) { + const uint8_t* p = static_cast(data); + uint64_t h = 0xcbf29ce484222325ULL; + for (size_t i = 0; i < len; ++i) + h = (h ^ p[i]) * 0x100000001b3ULL; + return h; +} + +)cpp"; + // Embed all files for (const auto& file : files) { std::ifstream in(file, std::ios::binary); diff --git a/test.sh b/test.sh new file mode 100755 index 0000000..ab2293a --- /dev/null +++ b/test.sh @@ -0,0 +1,34 @@ +#!/bin/bash +set -e + +SCRIPT_DIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd) + +TEST_DIR="$SCRIPT_DIR/test" + +rm -rf $TEST_DIR +mkdir $TEST_DIR + +#"$SCRIPT_DIR/build.sh" + +"$SCRIPT_DIR/output/dehydrate.amd64" src $TEST_DIR + +cat < test/main.cpp +#include "_src.hpp" + +#include +#include + +int main() { +// get the current path to this executable + std::filesystem::path exepath= std::filesystem::canonical("/proc/self/exe"); + recreate_src::recreate_tree(exepath.parent_path().string()+"/temp"); + return 0; +} +EOF + +g++ -std=c++17 -I $TEST_DIR -o $TEST_DIR/testexe $TEST_DIR/main.cpp $TEST_DIR/_src.cpp + +$TEST_DIR/testexe + +$TEST_DIR/testexe +