]> git.tdb.fi Git - builder.git/blobdiff - source/cache.cpp
Save caches before starting the build
[builder.git] / source / cache.cpp
index 70f4120d853d9dfb80073c9204e6e448d7089db4..de4643c4bf23abe1f9eb640a90756503d2e3313e 100644 (file)
@@ -1,5 +1,7 @@
 #include <msp/core/maputils.h>
+#include <msp/fs/dir.h>
 #include <msp/fs/stat.h>
+#include <msp/fs/utils.h>
 #include <msp/io/file.h>
 #include <msp/io/print.h>
 #include <msp/strings/utils.h>
@@ -57,7 +59,7 @@ void write_string(IO::Base &out, const string &str)
 
 Cache::Cache(SourcePackage &p):
        package(p),
-       filename(package.get_temp_dir()/"../cache"),
+       filename(package.get_temp_directory()/"../cache"),
        changed(false)
 { }
 
@@ -76,12 +78,14 @@ void Cache::append_value(const Target *tgt, const string &k, const string &v)
                i = data.insert(DataMap::value_type(key, ValueList())).first;
        i->second.push_back(v);
        changed = true;
+       package.get_builder().get_logger().log("cache", format("Updated key %s %s+ %s", tgt->get_name(), k, v));
 }
 
 void Cache::set_values(const Target *tgt, const string &k, const ValueList &v)
 {
        data[Key(tgt->get_name(), k)] = v;
        changed = true;
+       package.get_builder().get_logger().log("cache", format("Updated key %s %s: %s", tgt->get_name(), k, join(v.begin(), v.end())));
 }
 
 const string &Cache::get_value(const Target *tgt, const string &k)
@@ -119,6 +123,7 @@ void Cache::load()
                        ValueList &values = data[key];
                        for(unsigned count = read_count(in); count; --count)
                                values.push_back(read_string(in));
+                       package.get_builder().get_logger().log("cache", format("Loaded key %s %s: %s", key.first, key.second, join(values.begin(), values.end())));
                }
 
                mtime = st.get_modify_time();
@@ -130,6 +135,9 @@ void Cache::save() const
        if(data.empty() || !changed)
                return;
 
+       FS::Path dir = FS::dirname(filename);
+       if(!FS::exists(dir))
+               FS::mkpath(dir, 0755);
        package.get_builder().get_logger().log("files", format("Writing %s", filename));
        IO::BufferedFile out(filename.str(), IO::M_WRITE);
 
@@ -141,4 +149,6 @@ void Cache::save() const
                for(ValueList::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
                        write_string(out, *j);
        }
+
+       changed = false;
 }