Skip to content

Commit e43edbe

Browse files
committed
feat: storing source file hashes
1 parent 1047b89 commit e43edbe

File tree

1 file changed

+50
-1
lines changed

1 file changed

+50
-1
lines changed

src/main.cpp2

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -828,10 +828,14 @@ do_build: (targets: std::vector<std::string>) -> (stuff: full_build_info, exit_c
828828
transpile_futures: std::vector<std::future<transpile_cpp2_result>> = ();
829829
cpp2b_parse_futures: std::vector<std::future<cpp2b_source_info>> = ();
830830
file_hash_futures: std::unordered_map<fs::path, std::future<u64>> = ();
831+
file_hashes: std::unordered_map<fs::path, u64> = ();
832+
prev_file_hashes: std::unordered_map<fs::path, u64> = ();
831833

832834
transpile_futures.reserve(cpp2_source_files.size());
833835
cpp2b_parse_futures.reserve(cpp2_source_files.size());
834836
file_hash_futures.reserve(cpp2_source_files.size());
837+
file_hashes.reserve(cpp2_source_files.size());
838+
prev_file_hashes.reserve(cpp2_source_files.size());
835839

836840
for cpp2_source_files do(src_file: fs::path) {
837841
file_hash_futures.insert(std::make_pair(
@@ -846,8 +850,53 @@ do_build: (targets: std::vector<std::string>) -> (stuff: full_build_info, exit_c
846850
p := entry.first;
847851
hash_fut := entry.second&;
848852
hash := hash_fut*.get();
853+
file_hashes.insert(std::make_pair(p, hash));
854+
}
855+
856+
data_file: std::fstream = (".cache/cpp2/.data", std::ios::binary | std::ios::in);
857+
858+
while data_file {
859+
path_length: u16 = 0;
860+
data_file >> path_length;
861+
if !data_file { break; }
862+
863+
p: std::string = "";
864+
p.resize(path_length);
865+
data_file.read(p.data(), path_length);
866+
if !data_file { break; }
867+
868+
path_hash: u64 = 0;
869+
data_file.read(reinterpret_cast<*char>(path_hash&), 8);
870+
if !data_file { break; }
871+
872+
prev_file_hashes[fs::path(p)] = path_hash;
873+
}
874+
875+
for file_hashes do(inout entry) {
876+
p := entry.first;
877+
hash := entry.second;
878+
879+
if prev_file_hashes.contains(p) {
880+
if prev_file_hashes.at(p) == hash {
881+
log_info("{} no change", p.generic_string());
882+
} else {
883+
log_info("{} changed", p.generic_string());
884+
}
885+
} else {
886+
log_info("new file {}", p.generic_string());
887+
}
888+
}
889+
890+
data_file.close();
891+
data_file.open(".cache/cpp2/.data", std::ios::binary | std::ios::out | std::ios::trunc);
892+
893+
for file_hashes do(inout entry) {
894+
p := entry.first.generic_string();
895+
hash := entry.second;
849896

850-
log_info("{} hash is {}", p.generic_string(), hash);
897+
data_file << unsafe_cast<u16>(p.size());
898+
data_file.write(p.data(), p.size());
899+
data_file.write(reinterpret_cast<*char>(hash&), 8);
851900
}
852901

853902
for transpile_futures do(inout fut) {

0 commit comments

Comments
 (0)