world->prepare();
}
+ for(PackageMap::iterator i=packages.begin(); i!=packages.end(); ++i)
+ i->second->get_deps_cache().save();
+
return 0;
}
--- /dev/null
+/* $Id$
+
+This file is part of builder
+Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#include <fstream>
+#include <msp/path/utils.h>
+#include <msp/strings/utils.h>
+#include "builder.h"
+#include "dependencycache.h"
+#include "package.h"
+
+using namespace std;
+using namespace Msp;
+
+DependencyCache::DependencyCache(Package &p):
+ package(p),
+ changed(false)
+{ }
+
+const StringList &DependencyCache::get_deps(const string &tgt) const
+{
+ DepsMap::const_iterator i=deps.find(tgt);
+ if(i==deps.end())
+ {
+ static StringList dummy;
+ return dummy;
+ }
+ return i->second;
+}
+
+void DependencyCache::set_deps(const string &tgt, const StringList &d)
+{
+ deps[tgt]=d;
+ changed=true;
+}
+
+/**
+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())
+ return;
+
+ ofstream out((package.get_source()/".deps").str().c_str());
+ if(!out)
+ return;
+
+ for(DepsMap::const_iterator i=deps.begin(); i!=deps.end(); ++i)
+ {
+ out<<i->first;
+ for(StringList::const_iterator j=i->second.begin(); j!=i->second.end(); ++j)
+ out<<'|'<<*j;
+ out<<'\n';
+ }
+}
+
+void DependencyCache::load()
+{
+ string fn=(package.get_source()/".deps").str();
+ ifstream in(fn.c_str());
+ if(!in)
+ return;
+
+ string line;
+ while(getline(in, line))
+ {
+ vector<string> parts=split(line, '|');
+ deps[parts[0]]=StringList(parts.begin()+1, parts.end());
+ }
+
+ struct stat st;
+ Path::stat(fn, st);
+ mtime=Time::TimeStamp::from_unixtime(st.st_mtime);
+}
--- /dev/null
+/* $Id$
+
+This file is part of builder
+Copyright © 2006-2007 Mikko Rasa, Mikkosoft Productions
+Distributed under the LGPL
+*/
+
+#ifndef DEPENDENCYCACHE_H_
+#define DEPENDENCYCACHE_H_
+
+#include <msp/time/timestamp.h>
+#include "misc.h"
+
+class Package;
+
+/**
+Stores dependencies to avoid expensive operations during DAG building phase.
+The dependencies are stored in a map with target name as key and a list of
+strings as value. The targets are free to store whatever they want here.
+*/
+class DependencyCache
+{
+public:
+ DependencyCache(Package &p);
+ void set_deps(const std::string &tgt, const StringList &d);
+ const StringList &get_deps(const std::string &tgt) const;
+ const Msp::Time::TimeStamp &get_mtime() const { return mtime; }
+ void load();
+ void save() const;
+private:
+ typedef std::map<std::string, StringList> DepsMap;
+
+ Package &package;
+ DepsMap deps;
+ Msp::Time::TimeStamp mtime;
+ bool changed;
+};
+
+#endif
source(s),
config(*this),
conf_done(false),
+ deps_cache(*this),
use_pkgconfig(true),
need_path(false)
{
(*i)->set_path(config.get_option((*i)->get_name()+"_path").value);
(*i)->configure(opts, flag&2);
}
+
+ deps_cache.load();
}
create_build_info();
name(n),
buildable(false),
config(*this),
- conf_done(false)
+ conf_done(false),
+ deps_cache(*this)
{
for(vector<string>::const_iterator i=info.begin(); i!=info.end(); ++i)
{
export_binfo.unique();
}
+
Package::Loader::Loader(Package &p):
pkg(p)
{
#include "component.h"
#include "condition.h"
#include "config.h"
+#include "dependencycache.h"
#include "feature.h"
#include "packageref.h"
const std::string &get_arch() const { return config.get_option("arch").value; }
LibMode get_library_mode() const;
const PathList &get_tar_files() const { return tar_files; }
+ DependencyCache &get_deps_cache() const { return deps_cache; }
void resolve_refs();
void configure(const StringMap &, unsigned);
ComponentList components;
Config config;
bool conf_done;
+ mutable DependencyCache deps_cache;
PathList tar_files;
bool use_pkgconfig;
*/
void SourceFile::find_depends()
{
- ifstream in(name.c_str());
- if(!in) return;
+ DependencyCache &deps_cache=comp->get_package().get_deps_cache();
+ if(mtime>deps_cache.get_mtime())
+ {
+ ifstream in(name.c_str());
+ if(!in) return;
+
+ Regex r_include("^[ \t]*#include[ \t]+([\"<].*)[\">]");
- Regex r_include("^[ \t]*#include[ \t]+([\"<].*)[\">]");
+ string line;
+ while(getline(in, line))
+ if(RegMatch match=r_include.match(line))
+ includes.push_back(match[1].str);
- string line;
- while(getline(in, line))
- if(RegMatch match=r_include.match(line))
- includes.push_back(match[1].str);
+ deps_cache.set_deps(name, includes);
+ }
+ else
+ includes=deps_cache.get_deps(name);
const StringList &incpath=comp->get_build_info().incpath;
const string &arch=comp->get_package().get_arch();