diff options
Diffstat (limited to 'src/module.cc')
-rw-r--r-- | src/module.cc | 49 |
1 files changed, 31 insertions, 18 deletions
diff --git a/src/module.cc b/src/module.cc index 1f4059e..ccc475e 100644 --- a/src/module.cc +++ b/src/module.cc @@ -263,45 +263,58 @@ bool FileModule::handleDependencies() if (this->is_handling_dependencies) return false; this->is_handling_dependencies = true; - bool changed = false; + bool somethingchanged = false; + std::vector<std::pair<std::string,std::string> > updates; // 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 - FileModule::ModuleContainer::iterator iter = this->usedlibs.begin(); - while (iter != this->usedlibs.end()) { - FileModule::ModuleContainer::iterator curr = iter++; + BOOST_FOREACH(std::string filename, this->usedlibs) { bool wasmissing = false; + bool found = true; + // Get an absolute filename for the module - std::string filename = *curr; if (!boosty::is_absolute(filename)) { wasmissing = true; fs::path fullpath = find_valid_path(this->path, filename); - if (!fullpath.empty()) filename = boosty::stringy(fullpath); + if (!fullpath.empty()) { + updates.push_back(std::make_pair(filename, boosty::stringy(fullpath))); + filename = boosty::stringy(fullpath); + } + else { + found = false; + } } - FileModule *oldmodule = ModuleCache::instance()->lookup(filename); - FileModule *newmodule = ModuleCache::instance()->evaluate(filename); - // Detect appearance but not removal of files - if (newmodule && oldmodule != newmodule) { - changed = true; + if (found) { + bool wascached = ModuleCache::instance()->isCached(filename); + FileModule *oldmodule = ModuleCache::instance()->lookup(filename); + FileModule *newmodule; + bool changed = ModuleCache::instance()->evaluate(filename, newmodule); + // Detect appearance but not removal of files, and keep old module + // on compile errors (FIXME: Is this correct behavior?) + if (changed) { #ifdef DEBUG - PRINTB_NOCACHE(" %s: %p -> %p", filename % oldmodule % newmodule); + PRINTB_NOCACHE(" %s: %p -> %p", filename % oldmodule % newmodule); #endif - } - if (!newmodule) { + } + somethingchanged |= changed; // Only print warning if we're not part of an automatic reload - if (!oldmodule && !wasmissing) { + if (!newmodule && !wascached && !wasmissing) { PRINTB_NOCACHE("WARNING: Failed to compile library '%s'.", filename); } } } + // Relative filenames which were located is reinserted as absolute filenames + typedef std::pair<std::string,std::string> stringpair; + BOOST_FOREACH(const stringpair &files, updates) { + this->usedlibs.erase(files.first); + this->usedlibs.insert(files.second); + } this->is_handling_dependencies = false; - return changed; + return somethingchanged; } AbstractNode *FileModule::instantiate(const Context *ctx, const ModuleInstantiation *inst, const EvalContext *evalctx) const |