From bba6f927e90f32e7051d5f8e0e1dfa5ae4413ff2 Mon Sep 17 00:00:00 2001 From: Christian Kandeler Date: Thu, 26 Feb 2015 15:14:29 +0100 Subject: [PATCH] Don't attempt to analyze using icecc masquerading as clang. Also warn the user in the settings page against this. Change-Id: I4dbae953aa85f8dbdc9baa8dd0fda8ff0da45b76 Reviewed-by: Nikolai Kosjar --- .../clangstaticanalyzer.pro | 2 + .../clangstaticanalyzer.qbs | 2 + .../clangstaticanalyzerconfigwidget.cpp | 4 -- .../clangstaticanalyzerconfigwidget.ui | 6 +-- .../clangstaticanalyzerpathchooser.cpp | 40 +++++++++++++++++++ .../clangstaticanalyzerpathchooser.h | 40 +++++++++++++++++++ .../clangstaticanalyzerutils.cpp | 18 ++++++++- .../clangstaticanalyzerutils.h | 4 +- 8 files changed, 106 insertions(+), 10 deletions(-) create mode 100644 plugins/clangstaticanalyzer/clangstaticanalyzerpathchooser.cpp create mode 100644 plugins/clangstaticanalyzer/clangstaticanalyzerpathchooser.h diff --git a/plugins/clangstaticanalyzer/clangstaticanalyzer.pro b/plugins/clangstaticanalyzer/clangstaticanalyzer.pro index df939e9f36c..38ddda3e641 100644 --- a/plugins/clangstaticanalyzer/clangstaticanalyzer.pro +++ b/plugins/clangstaticanalyzer/clangstaticanalyzer.pro @@ -10,6 +10,7 @@ SOURCES += \ clangstaticanalyzerdiagnosticmodel.cpp \ clangstaticanalyzerdiagnosticview.cpp \ clangstaticanalyzerlogfilereader.cpp \ + clangstaticanalyzerpathchooser.cpp \ clangstaticanalyzerplugin.cpp \ clangstaticanalyzerruncontrol.cpp \ clangstaticanalyzerruncontrolfactory.cpp \ @@ -26,6 +27,7 @@ HEADERS += \ clangstaticanalyzerdiagnosticview.h \ clangstaticanalyzer_global.h \ clangstaticanalyzerlogfilereader.h \ + clangstaticanalyzerpathchooser.h \ clangstaticanalyzerplugin.h \ clangstaticanalyzerruncontrolfactory.h \ clangstaticanalyzerruncontrol.h \ diff --git a/plugins/clangstaticanalyzer/clangstaticanalyzer.qbs b/plugins/clangstaticanalyzer/clangstaticanalyzer.qbs index 78c7decc5df..9113cc94c30 100644 --- a/plugins/clangstaticanalyzer/clangstaticanalyzer.qbs +++ b/plugins/clangstaticanalyzer/clangstaticanalyzer.qbs @@ -28,6 +28,8 @@ QtcPlugin { "clangstaticanalyzerdiagnosticview.h", "clangstaticanalyzerlogfilereader.cpp", "clangstaticanalyzerlogfilereader.h", + "clangstaticanalyzerpathchooser.cpp", + "clangstaticanalyzerpathchooser.h", "clangstaticanalyzerplugin.cpp", "clangstaticanalyzerplugin.h", "clangstaticanalyzerruncontrol.cpp", diff --git a/plugins/clangstaticanalyzer/clangstaticanalyzerconfigwidget.cpp b/plugins/clangstaticanalyzer/clangstaticanalyzerconfigwidget.cpp index d6ff0fa5b84..6b8b0f0cee2 100644 --- a/plugins/clangstaticanalyzer/clangstaticanalyzerconfigwidget.cpp +++ b/plugins/clangstaticanalyzer/clangstaticanalyzerconfigwidget.cpp @@ -33,10 +33,6 @@ ClangStaticAnalyzerConfigWidget::ClangStaticAnalyzerConfigWidget( { m_ui->setupUi(this); - m_ui->clangExecutableChooser->setExpectedKind(Utils::PathChooser::ExistingCommand); - m_ui->clangExecutableChooser->setHistoryCompleter( - QLatin1String("ClangStaticAnalyzer.ClangCommand.History")); - m_ui->clangExecutableChooser->setPromptDialogTitle(tr("Clang Command")); m_ui->clangExecutableChooser->setPath(settings->clangExecutable()); connect(m_ui->clangExecutableChooser, &Utils::PathChooser::changed, m_settings, &ClangStaticAnalyzerSettings::setClangExecutable); diff --git a/plugins/clangstaticanalyzer/clangstaticanalyzerconfigwidget.ui b/plugins/clangstaticanalyzer/clangstaticanalyzerconfigwidget.ui index 800733a3317..8997f3a7d11 100644 --- a/plugins/clangstaticanalyzer/clangstaticanalyzerconfigwidget.ui +++ b/plugins/clangstaticanalyzer/clangstaticanalyzerconfigwidget.ui @@ -30,7 +30,7 @@ - + @@ -88,9 +88,9 @@ - Utils::PathChooser + ClangStaticAnalyzer::Internal::PathChooser QWidget -
utils/pathchooser.h
+
clangstaticanalyzer/clangstaticanalyzerpathchooser.h
1
diff --git a/plugins/clangstaticanalyzer/clangstaticanalyzerpathchooser.cpp b/plugins/clangstaticanalyzer/clangstaticanalyzerpathchooser.cpp new file mode 100644 index 00000000000..b5711bfeab4 --- /dev/null +++ b/plugins/clangstaticanalyzer/clangstaticanalyzerpathchooser.cpp @@ -0,0 +1,40 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd +** All rights reserved. +** For any questions to The Qt Company, please use contact form at http://www.qt.io/contact-us +** +** This file is part of the Qt Enterprise LicenseChecker Add-on. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. +** +** If you have questions regarding the use of this file, please use +** contact form at http://www.qt.io/contact-us +** +****************************************************************************/ +#include "clangstaticanalyzerpathchooser.h" + +#include "clangstaticanalyzerutils.h" + +namespace ClangStaticAnalyzer { +namespace Internal { + +PathChooser::PathChooser(QWidget *parent) : Utils::PathChooser(parent) +{ + setExpectedKind(Utils::PathChooser::ExistingCommand); + setHistoryCompleter(QLatin1String("ClangStaticAnalyzer.ClangCommand.History")); + setPromptDialogTitle(tr("Clang Command")); +} + +bool PathChooser::validatePath(const QString &path, QString *errorMessage) +{ + if (!Utils::PathChooser::validatePath(path, errorMessage)) + return false; + return isClangExecutableUsable(fileName().toString(), errorMessage); +} + +} // namespace Internal +} // namespace ClangStaticAnalyzer diff --git a/plugins/clangstaticanalyzer/clangstaticanalyzerpathchooser.h b/plugins/clangstaticanalyzer/clangstaticanalyzerpathchooser.h new file mode 100644 index 00000000000..b4bc3c59476 --- /dev/null +++ b/plugins/clangstaticanalyzer/clangstaticanalyzerpathchooser.h @@ -0,0 +1,40 @@ +/**************************************************************************** +** +** Copyright (C) 2015 The Qt Company Ltd +** All rights reserved. +** For any questions to The Qt Company, please use contact form at http://www.qt.io/contact-us +** +** This file is part of the Qt Enterprise LicenseChecker Add-on. +** +** Licensees holding valid Qt Enterprise licenses may use this file in +** accordance with the Qt Enterprise License Agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. +** +** If you have questions regarding the use of this file, please use +** contact form at http://www.qt.io/contact-us +** +****************************************************************************/ +#ifndef QTC_CLANGSTATICANALYZER_PATHCHOOSER_H +#define QTC_CLANGSTATICANALYZER_PATHCHOOSER_H + +#include + +namespace ClangStaticAnalyzer { +namespace Internal { + +class PathChooser : public Utils::PathChooser +{ + Q_OBJECT + +public: + PathChooser(QWidget *parent = 0); + +private: + bool validatePath(const QString &path, QString *errorMessage = 0); +}; + +} // namespace Internal +} // namespace ClangStaticAnalyzer + +#endif // Include guard. diff --git a/plugins/clangstaticanalyzer/clangstaticanalyzerutils.cpp b/plugins/clangstaticanalyzer/clangstaticanalyzerutils.cpp index 06401eb2870..3860f929a6e 100644 --- a/plugins/clangstaticanalyzer/clangstaticanalyzerutils.cpp +++ b/plugins/clangstaticanalyzer/clangstaticanalyzerutils.cpp @@ -23,6 +23,7 @@ #include +#include #include static bool isFileExecutable(const QString &executablePath) @@ -63,7 +64,7 @@ QString clangExecutable(const QString &fileNameOrPath, bool *isValid) executable = executableFromPath; } - *isValid = isFileExecutable(executable); + *isValid = isFileExecutable(executable) && isClangExecutableUsable(executable); return executable; } @@ -74,5 +75,20 @@ QString createFullLocationString(const ClangStaticAnalyzer::Internal::Location & return filePath + QLatin1Char(':') + lineNumber; } +bool isClangExecutableUsable(const QString &filePath, QString *errorMessage) +{ + const QFileInfo fi(filePath); + if (fi.isSymLink() && fi.symLinkTarget().contains(QLatin1String("icecc"))) { + if (errorMessage) { + *errorMessage = QCoreApplication::translate("ClangStaticAnalyzer", + "The chosen file \"%1\" seems to point to an icecc binary not suitable " + "for analyzing.\nPlease set a real clang executable.") + .arg(filePath); + } + return false; + } + return true; +} + } // namespace Internal } // namespace ClangStaticAnalyzer diff --git a/plugins/clangstaticanalyzer/clangstaticanalyzerutils.h b/plugins/clangstaticanalyzer/clangstaticanalyzerutils.h index e85d25f2868..ca06c4874e5 100644 --- a/plugins/clangstaticanalyzer/clangstaticanalyzerutils.h +++ b/plugins/clangstaticanalyzer/clangstaticanalyzerutils.h @@ -25,13 +25,13 @@ QT_BEGIN_NAMESPACE class QString; QT_END_NAMESPACE - - namespace ClangStaticAnalyzer { namespace Internal { class Location; +bool isClangExecutableUsable(const QString &filePath, QString *errorMessage = 0); + QString clangExecutable(const QString &fileNameOrPath, bool *isValid); QString clangExecutableFromSettings(const QString &toolchainType, bool *isValid);