]> git.tdb.fi Git - builder.git/blobdiff - source/dependencycache.cpp
Rearrange Target members
[builder.git] / source / dependencycache.cpp
index b2ba4e8ce953e9b92bd41d4c66443bf24c749237..15abf0858b054f7df80563f887dc63c54a344679 100644 (file)
@@ -1,12 +1,5 @@
-/* $Id$
-
-This file is part of builder
-Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
-Distributed under the LGPL
-*/
-
+#include <msp/core/maputils.h>
 #include <msp/fs/stat.h>
-#include <msp/io/except.h>
 #include <msp/io/file.h>
 #include <msp/io/print.h>
 #include <msp/strings/utils.h>
@@ -22,28 +15,25 @@ DependencyCache::DependencyCache(SourcePackage &p):
        changed(false)
 { }
 
-const StringList &DependencyCache::get_deps(const string &tgt) const
+void DependencyCache::set_deps(const string &tgt, const StringList &d)
 {
-       DepsMap::const_iterator i=deps.find(tgt);
-       if(i==deps.end())
-               throw KeyError("Unknown dependencies", tgt);
+       deps[tgt] = d;
+       changed = true;
+}
 
-       return i->second;
+bool DependencyCache::has_deps(const string &tgt) const
+{
+       return deps.count(tgt);
 }
 
-void DependencyCache::set_deps(const string &tgt, const StringList &d)
+const StringList &DependencyCache::get_deps(const string &tgt) const
 {
-       deps[tgt]=d;
-       changed=true;
+       return get_item(deps, tgt);
 }
 
-/**
-Saves the depencency cache.  If there are no cached dependencies or they
-haven't been changed, does nothing.
-*/
 void DependencyCache::save() const
 {
-       if(deps.empty() || !changed || package.get_builder().get_dry_run())
+       if(deps.empty() || !changed)
                return;
 
        IO::BufferedFile out((package.get_source()/".deps").str(), IO::M_WRITE);
@@ -59,21 +49,19 @@ void DependencyCache::save() const
 
 void DependencyCache::load()
 {
-       string fn=(package.get_source()/".deps").str();
+       string fn = (package.get_source()/".deps").str();
 
-       try
+       if(FS::Stat st = FS::stat(fn))
        {
                IO::BufferedFile in(fn);
 
                string line;
                while(in.getline(line))
                {
-                       vector<string> parts=split(line, '|');
-                       deps[parts[0]]=StringList(parts.begin()+1, parts.end());
+                       vector<string> parts = split(line, '|');
+                       deps[parts[0]] = StringList(parts.begin()+1, parts.end());
                }
 
-               mtime=Time::TimeStamp::from_unixtime(FS::stat(fn).st_mtime);
+               mtime = st.get_modify_time();
        }
-       catch(const IO::FileNotFound &)
-       { }
 }