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 IO::BufferedFile out((package.get_source()/".deps").str(), IO::M_WRITE);
41 for(DepsMap::const_iterator i=deps.begin(); i!=deps.end(); ++i)
43 IO::print(out, i->first);
44 for(StringList::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
45 IO::print(out, "|%s", *j);
50 void DependencyCache::load()
52 string fn = (package.get_source()/".deps").str();
54 if(FS::Stat st = FS::stat(fn))
56 IO::BufferedFile in(fn);
59 while(in.getline(line))
61 vector<string> parts = split(line, '|');
62 deps[parts[0]] = StringList(parts.begin()+1, parts.end());
65 mtime = st.get_modify_time();