1
0
Fork 0

make feature-order more deterministic

This commit is contained in:
jsteemann 2017-05-04 00:40:44 +02:00
parent e93d12cf31
commit a901b1e8fd
1 changed files with 14 additions and 22 deletions

View File

@ -384,35 +384,27 @@ void ApplicationServer::setupDependencies(bool failOnMissing) {
// first insert all features, even the inactive ones // first insert all features, even the inactive ones
std::vector<ApplicationFeature*> features; std::vector<ApplicationFeature*> features;
for (auto& it : _features) { for (auto& it : _features) {
auto const& us = it.second;
auto insertPosition = features.end(); auto insertPosition = features.end();
if (!features.empty()) { for (size_t i = features.size(); i > 0; --i) {
for (size_t i = features.size(); i > 0; --i) { auto const& other = features[i - 1];
if (it.second->doesStartBefore(features[i - 1]->name())) { if (us->doesStartBefore(other->name())) {
// we start before the other feature. so move ourselves up
insertPosition = features.begin() + (i - 1);
} else if (other->doesStartBefore(us->name())) {
// the other feature starts before us. so stop moving up
break;
} else {
// no dependencies between the two features
if (us->name() < other->name()) {
insertPosition = features.begin() + (i - 1); insertPosition = features.begin() + (i - 1);
} }
} }
} }
features.insert(insertPosition, it.second); features.insert(insertPosition, it.second);
} }
for (size_t i = 1; i < features.size(); ++i) {
auto feature = features[i];
size_t insert = i;
for (size_t j = i; j > 0; --j) {
if (features[j - 1]->doesStartBefore(feature->name())) {
break;
}
insert = j - 1;
}
if (insert != i) {
for (size_t j = i; j > insert; --j) {
features[j] = features[j - 1];
}
features[insert] = feature;
}
}
LOG_TOPIC(TRACE, Logger::STARTUP) << "ordered features:"; LOG_TOPIC(TRACE, Logger::STARTUP) << "ordered features:";
int position = 0; int position = 0;
@ -425,7 +417,7 @@ void ApplicationServer::setupDependencies(bool failOnMissing) {
} }
LOG_TOPIC(TRACE, Logger::STARTUP) LOG_TOPIC(TRACE, Logger::STARTUP)
<< "feature #" << ++position << ": " << feature->name() << "feature #" << ++position << ": " << feature->name()
<< (feature->isEnabled() ? "" : " (disabled)") << " " << dependencies; << (feature->isEnabled() ? "" : " (disabled)") << dependencies;
} }
// remove all inactive features // remove all inactive features