server: Cache a hash of each compiled module in order not to rebuild them unnecessarily
This commit is contained in:
parent
07f1a22eaa
commit
2c0400f975
@ -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
|
||||
|
@ -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 <c55/string_util.h>
|
||||
@ -80,6 +81,18 @@ static sv_<ss_> list_includes(const ss_ &path, const sv_<ss_> &include_dirs)
|
||||
return result;
|
||||
}
|
||||
|
||||
static ss_ hash_files(const sv_<ss_> &paths)
|
||||
{
|
||||
std::ostringstream os(std::ios::binary);
|
||||
for(const ss_ &path : paths){
|
||||
std::ifstream f(path);
|
||||
std::string content((std::istreambuf_iterator<char>(f)),
|
||||
std::istreambuf_iterator<char>());
|
||||
os<<content;
|
||||
}
|
||||
return interface::sha1::calculate(os.str());
|
||||
}
|
||||
|
||||
struct BuildatResourceRouter : public magic::ResourceRouter
|
||||
{
|
||||
server::State *m_server;
|
||||
@ -366,6 +379,28 @@ struct CState: public State, public interface::Server
|
||||
|
||||
bool skip_compile = g_server_config.skip_compiling_modules.count(info.name);
|
||||
|
||||
if(!skip_compile){
|
||||
sv_<ss_> 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<char>(f)),
|
||||
std::istreambuf_iterator<char>());
|
||||
}
|
||||
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<<hash;
|
||||
}
|
||||
}
|
||||
|
||||
m_compiler->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);
|
||||
|
Loading…
x
Reference in New Issue
Block a user