1 #include <msp/core/maputils.h>
2 #include <msp/fs/stat.h>
3 #include <msp/io/file.h>
4 #include <msp/io/print.h>
5 #include <msp/strings/utils.h>
7 #include "dependencycache.h"
8 #include "sourcepackage.h"
13 DependencyCache::DependencyCache(SourcePackage &p):
18 void DependencyCache::set_deps(const string &tgt, const StringList &d)
24 bool DependencyCache::has_deps(const string &tgt) const
26 return deps.count(tgt);
29 const StringList &DependencyCache::get_deps(const string &tgt) const
31 return get_item(deps, tgt);
34 void DependencyCache::save() const
36 if(deps.empty() || !changed)
39 FS::Path fn = package.get_source_directory()/".deps";
40 package.get_builder().get_logger().log("files", format("Writing %s", fn));
41 IO::BufferedFile out(fn.str(), IO::M_WRITE);
43 for(DepsMap::const_iterator i=deps.begin(); i!=deps.end(); ++i)
45 IO::print(out, i->first);
46 for(StringList::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
47 IO::print(out, "|%s", *j);
52 void DependencyCache::load()
54 FS::Path fn = package.get_source_directory()/".deps";
56 if(FS::Stat st = FS::stat(fn))
58 package.get_builder().get_logger().log("files", format("Reading %s", fn));
59 IO::BufferedFile in(fn.str());
62 while(in.getline(line))
64 vector<string> parts = split(line, '|');
65 deps[parts[0]] = StringList(parts.begin()+1, parts.end());
68 mtime = st.get_modify_time();