]> git.tdb.fi Git - builder.git/blob - source/dependencycache.cpp
Replace per-file copyright notices with a single file
[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 const StringList &DependencyCache::get_deps(const string &tgt) const
25 {
26         return get_item(deps, tgt);
27 }
28
29 void DependencyCache::save() const
30 {
31         if(deps.empty() || !changed || package.get_builder().get_dry_run())
32                 return;
33
34         IO::BufferedFile out((package.get_source()/".deps").str(), IO::M_WRITE);
35
36         for(DepsMap::const_iterator i=deps.begin(); i!=deps.end(); ++i)
37         {
38                 IO::print(out, i->first);
39                 for(StringList::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
40                         IO::print(out, "|%s", *j);
41                 IO::print(out, "\n");
42         }
43 }
44
45 void DependencyCache::load()
46 {
47         string fn = (package.get_source()/".deps").str();
48
49         try
50         {
51                 IO::BufferedFile in(fn);
52
53                 string line;
54                 while(in.getline(line))
55                 {
56                         vector<string> parts = split(line, '|');
57                         deps[parts[0]] = StringList(parts.begin()+1, parts.end());
58                 }
59
60                 mtime = FS::stat(fn).get_modify_time();
61         }
62         catch(const IO::file_not_found &)
63         { }
64 }