diff --git a/doc/todo.txt b/doc/todo.txt index a4a3dc9..e5dd31f 100644 --- a/doc/todo.txt +++ b/doc/todo.txt @@ -1,7 +1,5 @@ Buildat TODO ============ -- Cache a hash of each compiled module in order not to rebuild them - unnecessarily - Modules should be run in threads. - Include hmmmm/kwolekr's MT noise under interfaces (Simplified BSD) - Design how to manage scenes in a future-proof way diff --git a/src/server/state.cpp b/src/server/state.cpp index 6754924..c833be4 100644 --- a/src/server/state.cpp +++ b/src/server/state.cpp @@ -11,6 +11,7 @@ #include "interface/file_watch.h" #include "interface/fs.h" #include "interface/magic_event.h" +#include "interface/sha1.h" //#include "interface/thread.h" #include "interface/mutex.h" #include @@ -80,6 +81,18 @@ static sv_ list_includes(const ss_ &path, const sv_ &include_dirs) return result; } +static ss_ hash_files(const sv_ &paths) +{ + std::ostringstream os(std::ios::binary); + for(const ss_ &path : paths){ + std::ifstream f(path); + std::string content((std::istreambuf_iterator(f)), + std::istreambuf_iterator()); + os< files_to_hash = {init_cpp_path}; + files_to_hash.insert( + files_to_hash.begin(), includes.begin(), includes.end()); + ss_ hash = hash_files(files_to_hash); + log_d(MODULE, "Hash: %s", cs(interface::sha1::hex(hash))); + ss_ hashfile_path = build_dst+".hash"; + ss_ previous_hash; + { + std::ifstream f(hashfile_path); + previous_hash = ss_((std::istreambuf_iterator(f)), + std::istreambuf_iterator()); + } + if(previous_hash == hash){ + log_v(MODULE, "No need to recompile %s", cs(info.name)); + skip_compile = true; + } else { + std::ofstream f(hashfile_path); + f<include_directories.push_back(m_modules_path); bool build_ok = m_compiler->build(info.name, init_cpp_path, build_dst, extra_cxxflags, extra_ldflags, skip_compile);