Clang: Fix accepting absolute path clang executable

Commit 506fc40a31 broke running the analyzer with
absolute paths.

If the clang executable name is provided, the ".exe" suffix is not needed since
we get the absolute path with Utils::Environment::searchInPath(). However, for
absolute path we need to ensure the presence of the suffix in order to point to
an actually existing file.

Also, compare case insensitive.

Task-number: QTCREATORBUG-16234
Change-Id: I9f39386c099cc544297239eca56a95c2e7430555
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
Reviewed-by: Alessandro Portale <alessandro.portale@theqtcompany.com>
Reviewed-by: Tim Jenssen <tim.jenssen@theqtcompany.com>
This commit is contained in:
Nikolai Kosjar
2016-05-11 15:52:55 +02:00
committed by Nikolai Kosjar
parent bebdad0df1
commit a592f9b37a
2 changed files with 18 additions and 15 deletions

View File

@@ -50,25 +50,29 @@ namespace Internal {
QString clangExecutableFromSettings(Core::Id toolchainType, bool *isValid)
{
QString exeFromSettings = ClangStaticAnalyzerSettings::instance()->clangExecutable();
if (toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
if (exeFromSettings.endsWith(QLatin1String(QTC_HOST_EXE_SUFFIX)))
exeFromSettings.chop(int(qstrlen(QTC_HOST_EXE_SUFFIX)));
if (exeFromSettings.endsWith(QLatin1String("clang")))
exeFromSettings.append(QLatin1String("-cl"));
}
return clangExecutable(exeFromSettings, isValid);
}
QString clangExecutable(const QString &fileNameOrPath, bool *isValid)
{
QString executable = fileNameOrPath;
QString executable = ClangStaticAnalyzerSettings::instance()->clangExecutable();
if (executable.isEmpty()) {
*isValid = false;
return executable;
}
if (!QFileInfo(executable).isAbsolute()) {
const QString hostExeSuffix = QLatin1String(QTC_HOST_EXE_SUFFIX);
const Qt::CaseSensitivity caseSensitivity = Utils::HostOsInfo::fileNameCaseSensitivity();
const bool hasSuffix = executable.endsWith(hostExeSuffix, caseSensitivity);
if (toolchainType == ProjectExplorer::Constants::MSVC_TOOLCHAIN_TYPEID) {
if (hasSuffix)
executable.chop(hostExeSuffix.length());
executable.append(QLatin1String("-cl"));
if (hasSuffix)
executable.append(hostExeSuffix);
}
const QFileInfo fileInfo = QFileInfo(executable);
if (fileInfo.isAbsolute()) {
if (!hasSuffix)
executable.append(hostExeSuffix);
} else {
const Utils::Environment &environment = Utils::Environment::systemEnvironment();
const QString executableFromPath = environment.searchInPath(executable).toString();
if (executableFromPath.isEmpty()) {