X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fdependencycache.cpp;h=15abf0858b054f7df80563f887dc63c54a344679;hb=b067981c0da0c1a4616ed175d0ce8ac5564cbdbf;hp=0d82d7027baffc66aba49611cfd026c554a7544c;hpb=654de39b62a9a58fd8e1b5a557361d628345788b;p=builder.git diff --git a/source/dependencycache.cpp b/source/dependencycache.cpp index 0d82d70..15abf08 100644 --- a/source/dependencycache.cpp +++ b/source/dependencycache.cpp @@ -1,12 +1,7 @@ -/* $Id$ - -This file is part of builder -Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#include -#include +#include +#include +#include +#include #include #include "builder.h" #include "dependencycache.h" @@ -20,60 +15,53 @@ 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()) - { - static StringList dummy; - return dummy; - } - return i->second; + deps[tgt] = d; + changed = true; } -void DependencyCache::set_deps(const string &tgt, const StringList &d) +bool DependencyCache::has_deps(const string &tgt) const +{ + return deps.count(tgt); +} + +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; - ofstream out((package.get_source()/".deps").str().c_str()); - if(!out) - return; + IO::BufferedFile out((package.get_source()/".deps").str(), IO::M_WRITE); for(DepsMap::const_iterator i=deps.begin(); i!=deps.end(); ++i) { - out<first; + IO::print(out, i->first); for(StringList::const_iterator j=i->second.begin(); j!=i->second.end(); ++j) - out<<'|'<<*j; - out<<'\n'; + IO::print(out, "|%s", *j); + IO::print(out, "\n"); } } void DependencyCache::load() { - string fn=(package.get_source()/".deps").str(); - ifstream in(fn.c_str()); - if(!in) - return; + string fn = (package.get_source()/".deps").str(); - string line; - while(getline(in, line)) + if(FS::Stat st = FS::stat(fn)) { - vector parts=split(line, '|'); - deps[parts[0]]=StringList(parts.begin()+1, parts.end()); - } + IO::BufferedFile in(fn); - struct stat st; - Path::stat(fn, st); - mtime=Time::TimeStamp::from_unixtime(st.st_mtime); + string line; + while(in.getline(line)) + { + vector parts = split(line, '|'); + deps[parts[0]] = StringList(parts.begin()+1, parts.end()); + } + + mtime = st.get_modify_time(); + } }