summaryrefslogtreecommitdiff
path: root/src/module.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/module.cc')
-rw-r--r--src/module.cc66
1 files changed, 44 insertions, 22 deletions
diff --git a/src/module.cc b/src/module.cc
index 425403b..b9b23d8 100644
--- a/src/module.cc
+++ b/src/module.cc
@@ -147,7 +147,7 @@ public:
~ModRecursionGuard() {
inst.recursioncount--;
}
- bool recursion_detected() const { return (inst.recursioncount > 100); }
+ bool recursion_detected() const { return (inst.recursioncount > 1000); }
private:
const ModuleInstantiation &inst;
};
@@ -207,6 +207,28 @@ void FileModule::registerInclude(const std::string &localpath,
this->includes[localpath] = inc;
}
+bool FileModule::includesChanged() const
+{
+ BOOST_FOREACH(const FileModule::IncludeContainer::value_type &item, this->includes) {
+ if (include_modified(item.second)) return true;
+ }
+ return false;
+}
+
+bool FileModule::include_modified(const IncludeFile &inc) const
+{
+ struct stat st;
+ memset(&st, 0, sizeof(struct stat));
+
+ fs::path fullpath = find_valid_path(this->path, inc.filename);
+ bool valid = !fullpath.empty() ? (stat(boosty::stringy(fullpath).c_str(), &st) == 0) : false;
+
+ if (valid && !inc.valid) return true; // Detect appearance of file but not removal
+ if (valid && st.st_mtime > inc.mtime) return true;
+
+ return false;
+}
+
/*!
Check if any dependencies have been modified and recompile them.
Returns true if anything was recompiled.
@@ -217,34 +239,48 @@ bool FileModule::handleDependencies()
this->is_handling_dependencies = true;
bool changed = false;
- // Iterating manually since we want to modify the container while iterating
-
// If a lib in usedlibs was previously missing, we need to relocate it
// by searching the applicable paths. We can identify a previously missing module
// as it will have a relative path.
+
+ // Iterating manually since we want to modify the container while iterating
+ std::vector<std::pair<std::string, FileModule*> > modified_modules;
FileModule::ModuleContainer::iterator iter = this->usedlibs.begin();
while (iter != this->usedlibs.end()) {
FileModule::ModuleContainer::iterator curr = iter++;
FileModule *oldmodule = curr->second;
+ bool wasmissing = false;
// Get an absolute filename for the module
std::string filename = curr->first;
if (!boosty::is_absolute(filename)) {
+ wasmissing = true;
fs::path fullpath = find_valid_path(this->path, filename);
if (!fullpath.empty()) filename = boosty::stringy(fullpath);
}
- curr->second = ModuleCache::instance()->evaluate(filename);
- if (curr->second != oldmodule) {
+ FileModule *newmodule = ModuleCache::instance()->evaluate(filename);
+ // Detect appearance but not removal of files
+ if (newmodule && oldmodule != newmodule) {
changed = true;
#ifdef DEBUG
- PRINTB_NOCACHE(" %s: %p", filename % curr->second);
+ PRINTB_NOCACHE(" %s: %p", filename % newmodule);
#endif
}
- if (!curr->second) {
- PRINTB_NOCACHE("WARNING: Failed to compile library '%s'.", filename);
+ if (newmodule) {
+ modified_modules.push_back(std::make_pair(filename, newmodule));
+ this->usedlibs.erase(curr);
}
+ else {
+ // Only print warning if we're not part of an automatic reload
+ if (!oldmodule && !wasmissing) {
+ PRINTB_NOCACHE("WARNING: Failed to compile library '%s'.", filename);
+ }
+ }
+ }
+ BOOST_FOREACH(const FileModule::ModuleContainer::value_type &mod, modified_modules) {
+ this->usedlibs[mod.first] = mod.second;
}
this->is_handling_dependencies = false;
@@ -267,17 +303,3 @@ AbstractNode *FileModule::instantiate(const Context *ctx, const ModuleInstantiat
return node;
}
-
-bool FileModule::include_modified(IncludeFile inc)
-{
- struct stat st;
- memset(&st, 0, sizeof(struct stat));
-
- fs::path fullpath = find_valid_path(this->path, inc.filename);
- bool valid = !fullpath.empty() ? (stat(boosty::stringy(fullpath).c_str(), &st) == 0) : false;
-
- if (valid != inc.valid) return true;
- if (valid && st.st_mtime > inc.mtime) return true;
-
- return false;
-}
contact: Jan Huwald // Impressum