]> git.tdb.fi Git - builder.git/blob - source/dependencycache.cpp
Fix cascading of BuildInfo
[builder.git] / source / dependencycache.cpp
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>
6 #include "builder.h"
7 #include "dependencycache.h"
8 #include "sourcepackage.h"
9
10 using namespace std;
11 using namespace Msp;
12
13 DependencyCache::DependencyCache(SourcePackage &p):
14         package(p),
15         changed(false)
16 { }
17
18 void DependencyCache::set_deps(const string &tgt, const StringList &d)
19 {
20         deps[tgt] = d;
21         changed = true;
22 }
23
24 bool DependencyCache::has_deps(const string &tgt) const
25 {
26         return deps.count(tgt);
27 }
28
29 const StringList &DependencyCache::get_deps(const string &tgt) const
30 {
31         return get_item(deps, tgt);
32 }
33
34 void DependencyCache::save() const
35 {
36         if(deps.empty() || !changed)
37                 return;
38
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);
42
43         for(DepsMap::const_iterator i=deps.begin(); i!=deps.end(); ++i)
44         {
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);
48                 IO::print(out, "\n");
49         }
50 }
51
52 void DependencyCache::load()
53 {
54         FS::Path fn = package.get_source_directory()/".deps";
55
56         if(FS::Stat st = FS::stat(fn))
57         {
58                 package.get_builder().get_logger().log("files", format("Reading %s", fn));
59                 IO::BufferedFile in(fn.str());
60
61                 string line;
62                 while(in.getline(line))
63                 {
64                         vector<string> parts = split(line, '|');
65                         deps[parts[0]] = StringList(parts.begin()+1, parts.end());
66                 }
67
68                 mtime = st.get_modify_time();
69         }
70 }