File indexing completed on 2024-04-28 04:38:09
0001 /* 0002 SPDX-FileCopyrightText: 2016 Carlos Nihelton <carlosnsoliveira@gmail.com> 0003 SPDX-FileCopyrightText: 2018 Friedrich W. H. Kossebau <kossebau@kde.org> 0004 0005 SPDX-License-Identifier: GPL-2.0-or-later 0006 */ 0007 0008 #include "checkset.h" 0009 0010 // plugin 0011 #include "debug.h" 0012 // KF 0013 #include <KProcess> 0014 0015 namespace ClangTidy 0016 { 0017 0018 void CheckSet::setClangTidyPath(const QString& path) 0019 { 0020 if (m_clangTidyPath == path) { 0021 return; 0022 } 0023 0024 m_clangTidyPath = path; 0025 0026 m_allChecks.clear(); 0027 0028 if (m_clangTidyPath.isEmpty()) { 0029 return; 0030 } 0031 0032 // TODO: make this async 0033 KProcess tidy; 0034 tidy << m_clangTidyPath << QStringLiteral("-checks=*") << QStringLiteral("--list-checks"); 0035 tidy.setOutputChannelMode(KProcess::OnlyStdoutChannel); 0036 tidy.start(); 0037 0038 if (!tidy.waitForStarted()) { 0039 qCDebug(KDEV_CLANGTIDY) << "Unable to execute clang-tidy."; 0040 return; 0041 } 0042 0043 tidy.closeWriteChannel(); 0044 if (!tidy.waitForFinished()) { 0045 qCDebug(KDEV_CLANGTIDY) << "Failed during clang-tidy execution."; 0046 return; 0047 } 0048 0049 QTextStream ios(&tidy); 0050 QString each; 0051 while (ios.readLineInto(&each)) { 0052 m_allChecks.append(each.trimmed()); 0053 } 0054 // Drop leading "Enabled checks:" line and trailing empty line 0055 if (m_allChecks.size() > 3) { 0056 m_allChecks.removeAt(m_allChecks.length() - 1); 0057 m_allChecks.removeAt(0); 0058 } 0059 0060 m_allChecks.removeDuplicates(); 0061 } 0062 0063 QStringList CheckSet::defaults() const 0064 { 0065 // TODO: read this from clang-tidy, to pick up global settings 0066 const QStringList defaultChecks{ 0067 QStringLiteral("clang-analyzer-*"), 0068 }; 0069 0070 return defaultChecks; 0071 } 0072 0073 }