Fix that plugins were wrongly indirectly enabled when testing

Since the disabling of all plugins except tested onces was implemented
as an afterthought, it did not update the indirectly enabled plugins.
Instead, update the list of enabled/disabled plugins in the
optionsparser like for the -(no)load options, and trigger the update of
indirectly enabled plugins afterwards. Also take test dependencies into
account when indirectly enabling plugins directly.

Change-Id: I59d6c05de69a3073576155f7bd6201f1cd44697c
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
This commit is contained in:
Eike Ziller
2017-08-16 13:50:24 +02:00
parent 03dce9a65f
commit 240aff88ab
6 changed files with 37 additions and 39 deletions

View File

@@ -91,9 +91,12 @@ bool OptionsParser::parse()
// probably a file or something // probably a file or something
m_pmPrivate->arguments << m_currentArg; m_pmPrivate->arguments << m_currentArg;
} }
if (PluginManager::testRunRequested()) {
m_isDependencyRefreshNeeded = true;
forceDisableAllPluginsExceptTestedAndForceEnabled();
}
if (m_isDependencyRefreshNeeded) if (m_isDependencyRefreshNeeded)
m_pmPrivate->resolveDependencies(); m_pmPrivate->enableDependenciesIndirectly();
m_pmPrivate->enableOnlyTestedSpecs();
return !m_hasError; return !m_hasError;
} }
@@ -260,6 +263,16 @@ bool OptionsParser::checkForUnknownOption()
return true; return true;
} }
void OptionsParser::forceDisableAllPluginsExceptTestedAndForceEnabled()
{
for (const PluginManagerPrivate::TestSpec &testSpec : m_pmPrivate->testSpecs)
testSpec.pluginSpec->d->setForceEnabled(true);
for (PluginSpec *spec : m_pmPrivate->pluginSpecs) {
if (!spec->isForceEnabled())
spec->d->setForceDisabled(true);
}
}
bool OptionsParser::nextToken(OptionsParser::TokenType type) bool OptionsParser::nextToken(OptionsParser::TokenType type)
{ {
if (m_it == m_end) { if (m_it == m_end) {

View File

@@ -60,6 +60,7 @@ private:
bool checkForPluginOption(); bool checkForPluginOption();
bool checkForProfilingOption(); bool checkForProfilingOption();
bool checkForUnknownOption(); bool checkForUnknownOption();
void forceDisableAllPluginsExceptTestedAndForceEnabled();
enum TokenType { OptionalToken, RequiredToken }; enum TokenType { OptionalToken, RequiredToken };
bool nextToken(TokenType type = OptionalToken); bool nextToken(TokenType type = OptionalToken);

View File

@@ -1488,6 +1488,7 @@ void PluginManagerPrivate::readPluginPaths()
pluginSpecs.append(spec); pluginSpecs.append(spec);
} }
resolveDependencies(); resolveDependencies();
enableDependenciesIndirectly();
// ensure deterministic plugin load order by sorting // ensure deterministic plugin load order by sorting
Utils::sort(pluginSpecs, &PluginSpec::name); Utils::sort(pluginSpecs, &PluginSpec::name);
emit q->pluginsChanged(); emit q->pluginsChanged();
@@ -1495,42 +1496,19 @@ void PluginManagerPrivate::readPluginPaths()
void PluginManagerPrivate::resolveDependencies() void PluginManagerPrivate::resolveDependencies()
{ {
foreach (PluginSpec *spec, pluginSpecs) { foreach (PluginSpec *spec, pluginSpecs)
spec->d->enabledIndirectly = false; // reset, is recalculated below
spec->d->resolveDependencies(pluginSpecs); spec->d->resolveDependencies(pluginSpecs);
}
Utils::reverseForeach(loadQueue(), [](PluginSpec *spec) {
spec->d->enableDependenciesIndirectly();
});
} }
void PluginManagerPrivate::enableOnlyTestedSpecs() void PluginManagerPrivate::enableDependenciesIndirectly()
{ {
if (testSpecs.isEmpty())
return;
QList<PluginSpec *> specsForTests;
foreach (const TestSpec &testSpec, testSpecs) {
QList<PluginSpec *> circularityCheckQueue;
loadQueue(testSpec.pluginSpec, specsForTests, circularityCheckQueue);
// add plugins that must be force loaded when running tests for the plugin
// (aka "test dependencies")
QHashIterator<PluginDependency, PluginSpec *> it(testSpec.pluginSpec->dependencySpecs());
while (it.hasNext()) {
it.next();
if (it.key().type != PluginDependency::Test)
continue;
PluginSpec *depSpec = it.value();
circularityCheckQueue.clear();
loadQueue(depSpec, specsForTests, circularityCheckQueue);
}
}
foreach (PluginSpec *spec, pluginSpecs) foreach (PluginSpec *spec, pluginSpecs)
spec->d->setForceDisabled(true); spec->d->enabledIndirectly = false;
foreach (PluginSpec *spec, specsForTests) { // cannot use reverse loadQueue here, because test dependencies can introduce circles
spec->d->setForceDisabled(false); QList<PluginSpec *> queue = Utils::filtered(pluginSpecs, &PluginSpec::isEffectivelyEnabled);
spec->d->setForceEnabled(true); while (!queue.isEmpty()) {
PluginSpec *spec = queue.takeFirst();
queue += spec->d->enableDependenciesIndirectly(containsTestSpec(spec));
} }
} }

View File

@@ -68,7 +68,7 @@ public:
QList<PluginSpec *> loadQueue(); QList<PluginSpec *> loadQueue();
void loadPlugin(PluginSpec *spec, PluginSpec::State destState); void loadPlugin(PluginSpec *spec, PluginSpec::State destState);
void resolveDependencies(); void resolveDependencies();
void enableOnlyTestedSpecs(); void enableDependenciesIndirectly();
void initProfiling(); void initProfiling();
void profilingSummary() const; void profilingSummary() const;
void profilingReport(const char *what, const PluginSpec *spec = 0); void profilingReport(const char *what, const PluginSpec *spec = 0);

View File

@@ -917,19 +917,25 @@ bool PluginSpecPrivate::resolveDependencies(const QList<PluginSpec *> &specs)
return true; return true;
} }
void PluginSpecPrivate::enableDependenciesIndirectly() // returns the plugins that it actually indirectly enabled
QList<PluginSpec *> PluginSpecPrivate::enableDependenciesIndirectly(bool enableTestDependencies)
{ {
if (!q->isEffectivelyEnabled()) // plugin not enabled, nothing to do if (!q->isEffectivelyEnabled()) // plugin not enabled, nothing to do
return; return {};
QList<PluginSpec *> enabled;
QHashIterator<PluginDependency, PluginSpec *> it(dependencySpecs); QHashIterator<PluginDependency, PluginSpec *> it(dependencySpecs);
while (it.hasNext()) { while (it.hasNext()) {
it.next(); it.next();
if (it.key().type != PluginDependency::Required) if (it.key().type != PluginDependency::Required
&& (!enableTestDependencies || it.key().type != PluginDependency::Test))
continue; continue;
PluginSpec *dependencySpec = it.value(); PluginSpec *dependencySpec = it.value();
if (!dependencySpec->isEffectivelyEnabled()) if (!dependencySpec->isEffectivelyEnabled()) {
dependencySpec->d->enabledIndirectly = true; dependencySpec->d->enabledIndirectly = true;
enabled << dependencySpec;
} }
}
return enabled;
} }
/*! /*!

View File

@@ -103,7 +103,7 @@ public:
static bool isValidVersion(const QString &version); static bool isValidVersion(const QString &version);
static int versionCompare(const QString &version1, const QString &version2); static int versionCompare(const QString &version1, const QString &version2);
void enableDependenciesIndirectly(); QList<PluginSpec *> enableDependenciesIndirectly(bool enableTestDependencies = false);
bool readMetaData(const QJsonObject &pluginMetaData); bool readMetaData(const QJsonObject &pluginMetaData);