2018-05-07 17:04:26 +02:00
|
|
|
/****************************************************************************
|
|
|
|
|
**
|
|
|
|
|
** Copyright (C) 2018 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
|
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator.
|
|
|
|
|
**
|
|
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
|
|
|
|
**
|
|
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
|
|
|
|
**
|
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
|
|
#include "clangtoolsprojectsettings.h"
|
2018-05-08 16:47:27 +02:00
|
|
|
#include "clangtoolsdiagnostic.h"
|
2018-05-07 17:04:26 +02:00
|
|
|
|
|
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
|
|
|
|
|
#include <utils/algorithm.h>
|
2018-05-08 16:47:27 +02:00
|
|
|
#include <utils/qtcassert.h>
|
2018-05-07 17:04:26 +02:00
|
|
|
|
|
|
|
|
namespace ClangTools {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2019-09-13 10:49:14 +02:00
|
|
|
static const char SETTINGS_KEY_MAIN[] = "ClangTools";
|
|
|
|
|
static const char SETTINGS_PREFIX[] = "ClangTools.";
|
2018-05-14 11:40:40 +02:00
|
|
|
static const char SETTINGS_KEY_USE_GLOBAL_SETTINGS[] = "ClangTools.UseGlobalSettings";
|
2018-05-07 17:04:26 +02:00
|
|
|
static const char SETTINGS_KEY_SELECTED_DIRS[] = "ClangTools.SelectedDirs";
|
|
|
|
|
static const char SETTINGS_KEY_SELECTED_FILES[] = "ClangTools.SelectedFiles";
|
2018-05-08 16:47:27 +02:00
|
|
|
static const char SETTINGS_KEY_SUPPRESSED_DIAGS[] = "ClangTools.SuppressedDiagnostics";
|
|
|
|
|
static const char SETTINGS_KEY_SUPPRESSED_DIAGS_FILEPATH[] = "ClangTools.SuppressedDiagnosticFilePath";
|
|
|
|
|
static const char SETTINGS_KEY_SUPPRESSED_DIAGS_MESSAGE[] = "ClangTools.SuppressedDiagnosticMessage";
|
|
|
|
|
static const char SETTINGS_KEY_SUPPRESSED_DIAGS_UNIQIFIER[] = "ClangTools.SuppressedDiagnosticUniquifier";
|
2018-05-07 17:04:26 +02:00
|
|
|
|
|
|
|
|
ClangToolsProjectSettings::ClangToolsProjectSettings(ProjectExplorer::Project *project)
|
|
|
|
|
: m_project(project)
|
|
|
|
|
{
|
|
|
|
|
load();
|
|
|
|
|
connect(project, &ProjectExplorer::Project::settingsLoaded,
|
|
|
|
|
this, &ClangToolsProjectSettings::load);
|
|
|
|
|
connect(project, &ProjectExplorer::Project::aboutToSaveSettings, this,
|
|
|
|
|
&ClangToolsProjectSettings::store);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClangToolsProjectSettings::~ClangToolsProjectSettings()
|
|
|
|
|
{
|
|
|
|
|
store();
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-08 16:47:27 +02:00
|
|
|
void ClangToolsProjectSettings::addSuppressedDiagnostic(const SuppressedDiagnostic &diag)
|
|
|
|
|
{
|
|
|
|
|
QTC_ASSERT(!m_suppressedDiagnostics.contains(diag), return);
|
|
|
|
|
m_suppressedDiagnostics << diag;
|
|
|
|
|
emit suppressedDiagnosticsChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangToolsProjectSettings::removeSuppressedDiagnostic(const SuppressedDiagnostic &diag)
|
|
|
|
|
{
|
|
|
|
|
const bool wasPresent = m_suppressedDiagnostics.removeOne(diag);
|
|
|
|
|
QTC_ASSERT(wasPresent, return);
|
|
|
|
|
emit suppressedDiagnosticsChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangToolsProjectSettings::removeAllSuppressedDiagnostics()
|
|
|
|
|
{
|
|
|
|
|
m_suppressedDiagnostics.clear();
|
|
|
|
|
emit suppressedDiagnosticsChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2019-09-13 10:49:14 +02:00
|
|
|
static QVariantMap convertToMapFromVersionBefore410(ProjectExplorer::Project *p)
|
|
|
|
|
{
|
|
|
|
|
// These keys haven't changed.
|
|
|
|
|
const QStringList keys = {
|
|
|
|
|
SETTINGS_KEY_SELECTED_DIRS,
|
|
|
|
|
SETTINGS_KEY_SELECTED_FILES,
|
|
|
|
|
SETTINGS_KEY_SUPPRESSED_DIAGS,
|
|
|
|
|
SETTINGS_KEY_USE_GLOBAL_SETTINGS,
|
|
|
|
|
"ClangTools.BuildBeforeAnalysis",
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QVariantMap map;
|
|
|
|
|
for (const QString &key : keys)
|
|
|
|
|
map.insert(key, p->namedSettings(key));
|
|
|
|
|
|
|
|
|
|
map.insert(SETTINGS_PREFIX + QString(diagnosticConfigIdKey),
|
|
|
|
|
p->namedSettings("ClangTools.DiagnosticConfig"));
|
|
|
|
|
|
|
|
|
|
return map;
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-07 17:04:26 +02:00
|
|
|
void ClangToolsProjectSettings::load()
|
|
|
|
|
{
|
2019-09-13 10:49:14 +02:00
|
|
|
// Load map
|
|
|
|
|
QVariantMap map = m_project->namedSettings(SETTINGS_KEY_MAIN).toMap();
|
|
|
|
|
|
|
|
|
|
bool write;
|
|
|
|
|
if (map.isEmpty()) {
|
|
|
|
|
if (!m_project->namedSettings(SETTINGS_KEY_SELECTED_DIRS).isNull()) {
|
|
|
|
|
map = convertToMapFromVersionBefore410(m_project);
|
|
|
|
|
write = true;
|
|
|
|
|
} else {
|
|
|
|
|
return; // Use defaults
|
|
|
|
|
}
|
|
|
|
|
}
|
2019-06-19 15:16:15 +02:00
|
|
|
|
2019-09-13 10:49:14 +02:00
|
|
|
// Read map
|
|
|
|
|
m_useGlobalSettings = map.value(SETTINGS_KEY_USE_GLOBAL_SETTINGS).toBool();
|
2018-05-07 17:04:26 +02:00
|
|
|
|
2019-09-13 10:49:14 +02:00
|
|
|
auto toFileName = [](const QString &s) { return Utils::FilePath::fromString(s); };
|
|
|
|
|
const QStringList dirs = map.value(SETTINGS_KEY_SELECTED_DIRS).toStringList();
|
2018-05-07 17:04:26 +02:00
|
|
|
m_selectedDirs = Utils::transform<QSet>(dirs, toFileName);
|
|
|
|
|
|
2019-09-13 10:49:14 +02:00
|
|
|
const QStringList files = map.value(SETTINGS_KEY_SELECTED_FILES).toStringList();
|
2018-05-07 17:04:26 +02:00
|
|
|
m_selectedFiles = Utils::transform<QSet>(files, toFileName);
|
2018-05-08 16:47:27 +02:00
|
|
|
|
2019-09-13 10:49:14 +02:00
|
|
|
const QVariantList list = map.value(SETTINGS_KEY_SUPPRESSED_DIAGS).toList();
|
2018-05-08 16:47:27 +02:00
|
|
|
foreach (const QVariant &v, list) {
|
|
|
|
|
const QVariantMap diag = v.toMap();
|
|
|
|
|
const QString fp = diag.value(SETTINGS_KEY_SUPPRESSED_DIAGS_FILEPATH).toString();
|
|
|
|
|
if (fp.isEmpty())
|
|
|
|
|
continue;
|
|
|
|
|
const QString message = diag.value(SETTINGS_KEY_SUPPRESSED_DIAGS_MESSAGE).toString();
|
|
|
|
|
if (message.isEmpty())
|
|
|
|
|
continue;
|
2019-05-28 13:49:26 +02:00
|
|
|
Utils::FilePath fullPath = Utils::FilePath::fromString(fp);
|
2019-05-15 14:54:25 +02:00
|
|
|
if (fullPath.toFileInfo().isRelative())
|
|
|
|
|
fullPath = m_project->projectDirectory().pathAppended(fp);
|
2018-05-08 16:47:27 +02:00
|
|
|
if (!fullPath.exists())
|
|
|
|
|
continue;
|
|
|
|
|
const int uniquifier = diag.value(SETTINGS_KEY_SUPPRESSED_DIAGS_UNIQIFIER).toInt();
|
2019-07-19 14:47:41 +02:00
|
|
|
m_suppressedDiagnostics << SuppressedDiagnostic(Utils::FilePath::fromString(fp),
|
|
|
|
|
message,
|
|
|
|
|
uniquifier);
|
2018-05-08 16:47:27 +02:00
|
|
|
}
|
|
|
|
|
emit suppressedDiagnosticsChanged();
|
2019-09-13 10:49:14 +02:00
|
|
|
|
|
|
|
|
m_runSettings.fromMap(map, SETTINGS_PREFIX);
|
|
|
|
|
|
|
|
|
|
if (write)
|
|
|
|
|
store(); // Store new settings format
|
2018-05-07 17:04:26 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangToolsProjectSettings::store()
|
|
|
|
|
{
|
2019-09-13 10:49:14 +02:00
|
|
|
QVariantMap map;
|
|
|
|
|
map.insert(SETTINGS_KEY_USE_GLOBAL_SETTINGS, m_useGlobalSettings);
|
2018-05-14 11:40:40 +02:00
|
|
|
|
2019-07-03 18:34:30 +02:00
|
|
|
const QStringList dirs = Utils::transform<QList>(m_selectedDirs, &Utils::FilePath::toString);
|
2019-09-13 10:49:14 +02:00
|
|
|
map.insert(SETTINGS_KEY_SELECTED_DIRS, dirs);
|
2018-05-07 17:04:26 +02:00
|
|
|
|
2019-07-03 18:34:30 +02:00
|
|
|
const QStringList files = Utils::transform<QList>(m_selectedFiles, &Utils::FilePath::toString);
|
2019-09-13 10:49:14 +02:00
|
|
|
map.insert(SETTINGS_KEY_SELECTED_FILES, files);
|
2018-05-08 16:47:27 +02:00
|
|
|
|
|
|
|
|
QVariantList list;
|
2019-09-13 10:49:14 +02:00
|
|
|
for (const SuppressedDiagnostic &diag : m_suppressedDiagnostics) {
|
2018-05-08 16:47:27 +02:00
|
|
|
QVariantMap diagMap;
|
|
|
|
|
diagMap.insert(SETTINGS_KEY_SUPPRESSED_DIAGS_FILEPATH, diag.filePath.toString());
|
|
|
|
|
diagMap.insert(SETTINGS_KEY_SUPPRESSED_DIAGS_MESSAGE, diag.description);
|
|
|
|
|
diagMap.insert(SETTINGS_KEY_SUPPRESSED_DIAGS_UNIQIFIER, diag.uniquifier);
|
|
|
|
|
list << diagMap;
|
|
|
|
|
}
|
2019-09-13 10:49:14 +02:00
|
|
|
map.insert(SETTINGS_KEY_SUPPRESSED_DIAGS, list);
|
2018-05-07 17:04:26 +02:00
|
|
|
|
2019-09-13 10:49:14 +02:00
|
|
|
m_runSettings.toMap(map, SETTINGS_PREFIX);
|
2018-05-14 11:40:40 +02:00
|
|
|
|
2019-09-13 10:49:14 +02:00
|
|
|
m_project->setNamedSettings(SETTINGS_KEY_MAIN, map);
|
2018-05-14 11:40:40 +02:00
|
|
|
}
|
|
|
|
|
|
2018-05-07 17:04:26 +02:00
|
|
|
ClangToolsProjectSettingsManager::ClangToolsProjectSettingsManager()
|
|
|
|
|
{
|
|
|
|
|
QObject::connect(ProjectExplorer::SessionManager::instance(),
|
|
|
|
|
&ProjectExplorer::SessionManager::aboutToRemoveProject,
|
|
|
|
|
&ClangToolsProjectSettingsManager::handleProjectToBeRemoved);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClangToolsProjectSettings *ClangToolsProjectSettingsManager::getSettings(
|
|
|
|
|
ProjectExplorer::Project *project)
|
|
|
|
|
{
|
|
|
|
|
auto &settings = m_settings[project];
|
|
|
|
|
if (!settings)
|
|
|
|
|
settings.reset(new ClangToolsProjectSettings(project));
|
|
|
|
|
return settings.data();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void ClangToolsProjectSettingsManager::handleProjectToBeRemoved(ProjectExplorer::Project *project)
|
|
|
|
|
{
|
|
|
|
|
m_settings.remove(project);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
ClangToolsProjectSettingsManager::SettingsMap ClangToolsProjectSettingsManager::m_settings;
|
|
|
|
|
|
2018-05-08 16:47:27 +02:00
|
|
|
SuppressedDiagnostic::SuppressedDiagnostic(const Diagnostic &diag)
|
2019-05-28 13:49:26 +02:00
|
|
|
: filePath(Utils::FilePath::fromString(diag.location.filePath))
|
2018-05-08 16:47:27 +02:00
|
|
|
, description(diag.description)
|
|
|
|
|
, uniquifier(diag.explainingSteps.count())
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2018-05-07 17:04:26 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace ClangTools
|