ClangTools: Allow selecting diagnostic config for project

When starting the Clazy/Tidy tool, allow to select the diagnostic
configuration for the run.

As a side effect, fix a race condition where the runner could end up
with no diagnostic config (removed during run) - copy the diagnostic
config instead of referencing/querying it by the id.

Change-Id: Iedafa8f31a3bbd233d65818fe8de16add1e4d443
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
This commit is contained in:
Nikolai Kosjar
2018-05-14 11:40:40 +02:00
parent 2522275b69
commit 9b74948a61
12 changed files with 206 additions and 25 deletions

View File

@@ -34,6 +34,8 @@
namespace ClangTools {
namespace Internal {
static const char SETTINGS_KEY_USE_GLOBAL_SETTINGS[] = "ClangTools.UseGlobalSettings";
static const char SETTINGS_KEY_DIAGNOSTIC_CONFIG[] = "ClangTools.DiagnosticConfig";
static const char SETTINGS_KEY_SELECTED_DIRS[] = "ClangTools.SelectedDirs";
static const char SETTINGS_KEY_SELECTED_FILES[] = "ClangTools.SelectedFiles";
static const char SETTINGS_KEY_SUPPRESSED_DIAGS[] = "ClangTools.SuppressedDiagnostics";
@@ -80,6 +82,11 @@ void ClangToolsProjectSettings::removeAllSuppressedDiagnostics()
void ClangToolsProjectSettings::load()
{
const QVariant useGlobalVariant = m_project->namedSettings(SETTINGS_KEY_USE_GLOBAL_SETTINGS);
m_useGlobalSettings = useGlobalVariant.isValid() ? useGlobalVariant.toBool() : true;
m_diagnosticConfig = Core::Id::fromSetting(
m_project->namedSettings(SETTINGS_KEY_DIAGNOSTIC_CONFIG));
auto toFileName = [](const QString &s) { return Utils::FileName::fromString(s); };
const QStringList dirs = m_project->namedSettings(SETTINGS_KEY_SELECTED_DIRS).toStringList();
@@ -115,6 +122,9 @@ void ClangToolsProjectSettings::load()
void ClangToolsProjectSettings::store()
{
m_project->setNamedSettings(SETTINGS_KEY_USE_GLOBAL_SETTINGS, m_useGlobalSettings);
m_project->setNamedSettings(SETTINGS_KEY_DIAGNOSTIC_CONFIG, m_diagnosticConfig.toSetting());
const QStringList dirs = Utils::transform(m_selectedDirs.toList(), &Utils::FileName::toString);
m_project->setNamedSettings(SETTINGS_KEY_SELECTED_DIRS, dirs);
@@ -134,6 +144,26 @@ void ClangToolsProjectSettings::store()
m_project->setNamedSettings(SETTINGS_KEY_SUPPRESSED_DIAGS, list);
}
bool ClangToolsProjectSettings::useGlobalSettings() const
{
return m_useGlobalSettings;
}
void ClangToolsProjectSettings::setUseGlobalSettings(bool useGlobalSettings)
{
m_useGlobalSettings = useGlobalSettings;
}
Core::Id ClangToolsProjectSettings::diagnosticConfig() const
{
return m_diagnosticConfig;
}
void ClangToolsProjectSettings::setDiagnosticConfig(const Core::Id &diagnosticConfig)
{
m_diagnosticConfig = diagnosticConfig;
}
ClangToolsProjectSettingsManager::ClangToolsProjectSettingsManager()
{
QObject::connect(ProjectExplorer::SessionManager::instance(),