aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDenis Shienkov <denis.shienkov@gmail.com>2019-07-14 19:35:56 +0300
committerDenis Shienkov <denis.shienkov@gmail.com>2019-07-16 12:51:02 +0000
commit973ec011fda30243579e76800ba52b1fab77eb39 (patch)
tree71d30b247c8c0861ade57a06a994822aa55e9917
parent7e0bd8554c175a0c11f45d5d3a987696127f6dda (diff)
qbs-setup-toolchains: Refactor and improve the code a bit
* Added 'QBS_SETUPTOOLCHAINS_' prefix to all ifdef guards. * Unified the parameters order for the createXyzProfile() functions. * Used QFileInfo instead of QString as a compiler path variable. Change-Id: Ib4cfafa8d5ad4fe9e8ca8b06e4cfc17eafc67626 Reviewed-by: Ivan Komissarov <ABBAPOH@gmail.com> Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r--src/app/qbs-setup-toolchains/clangclprobe.cpp18
-rw-r--r--src/app/qbs-setup-toolchains/clangclprobe.h14
-rw-r--r--src/app/qbs-setup-toolchains/commandlineparser.h3
-rw-r--r--src/app/qbs-setup-toolchains/gccprobe.cpp5
-rw-r--r--src/app/qbs-setup-toolchains/gccprobe.h7
-rw-r--r--src/app/qbs-setup-toolchains/iarewprobe.h6
-rw-r--r--src/app/qbs-setup-toolchains/keilprobe.h6
-rw-r--r--src/app/qbs-setup-toolchains/msvcprobe.cpp5
-rw-r--r--src/app/qbs-setup-toolchains/msvcprobe.h14
-rw-r--r--src/app/qbs-setup-toolchains/probe.cpp6
-rw-r--r--src/app/qbs-setup-toolchains/probe.h5
-rw-r--r--src/app/qbs-setup-toolchains/sdccprobe.h6
-rw-r--r--src/app/qbs-setup-toolchains/xcodeprobe.h6
13 files changed, 57 insertions, 44 deletions
diff --git a/src/app/qbs-setup-toolchains/clangclprobe.cpp b/src/app/qbs-setup-toolchains/clangclprobe.cpp
index 89075c5e8..a54705510 100644
--- a/src/app/qbs-setup-toolchains/clangclprobe.cpp
+++ b/src/app/qbs-setup-toolchains/clangclprobe.cpp
@@ -60,9 +60,9 @@ using qbs::Internal::Tr;
namespace {
-QString getToolchainInstallPath(const QString &compilerFilePath)
+QString getToolchainInstallPath(const QFileInfo &compiler)
{
- return QFileInfo(compilerFilePath).path(); // 1 level up
+ return compiler.path(); // 1 level up
}
Profile createProfileHelper(
@@ -119,19 +119,19 @@ QString findCompatibleVcsarsallBat()
} // namespace
-void createClangClProfile(
- const QString &profileName, const QString &compilerFilePath, Settings *settings)
+void createClangClProfile(const QFileInfo &compiler, Settings *settings,
+ const QString &profileName)
{
const auto compilerName = QStringLiteral("clang-cl");
const auto vcvarsallPath = findCompatibleVcsarsallBat();
if (vcvarsallPath.isEmpty()) {
qbsWarning()
<< Tr::tr("%1 requires installed Visual Studio 2017 or newer, but none was found.")
- .arg(compilerName);
+ .arg(compilerName);
return;
}
- const auto toolchainInstallPath = getToolchainInstallPath(compilerFilePath);
+ const auto toolchainInstallPath = getToolchainInstallPath(compiler);
const auto hostArch = QString::fromStdString(HostOsInfo::hostOSArchitecture());
createProfileHelper(settings, profileName, toolchainInstallPath, vcvarsallPath, hostArch);
}
@@ -144,8 +144,8 @@ void clangClProbe(Settings *settings, QList<Profile> &profiles)
{
const auto compilerName = QStringLiteral("clang-cl");
qbsInfo() << Tr::tr("Trying to detect %1...").arg(compilerName);
- const auto compilerFilePath = findExecutable(HostOsInfo::appendExecutableSuffix(compilerName));
- if (compilerFilePath.isEmpty()) {
+ const QFileInfo compiler = findExecutable(HostOsInfo::appendExecutableSuffix(compilerName));
+ if (!compiler.exists()) {
qbsInfo() << Tr::tr("%1 was not found.").arg(compilerName);
return;
}
@@ -162,7 +162,7 @@ void clangClProbe(Settings *settings, QList<Profile> &profiles)
QStringLiteral("x86_64"),
QStringLiteral("x86")
};
- const auto toolchainInstallPath = getToolchainInstallPath(compilerFilePath);
+ const auto toolchainInstallPath = getToolchainInstallPath(compiler);
for (const auto &arch: architectures) {
const auto profileName = QStringLiteral("clang-cl-%1").arg(arch);
auto profile = createProfileHelper(
diff --git a/src/app/qbs-setup-toolchains/clangclprobe.h b/src/app/qbs-setup-toolchains/clangclprobe.h
index 1e7724fbf..1afbbb1b8 100644
--- a/src/app/qbs-setup-toolchains/clangclprobe.h
+++ b/src/app/qbs-setup-toolchains/clangclprobe.h
@@ -37,19 +37,23 @@
**
****************************************************************************/
-#ifndef CLANGCLPROBE_H
-#define CLANGCLPROBE_H
+#ifndef QBS_SETUPTOOLCHAINS_CLANGCLPROBE_H
+#define QBS_SETUPTOOLCHAINS_CLANGCLPROBE_H
#include <QtCore/qlist.h>
+QT_BEGIN_NAMESPACE
+class QFileInfo;
+QT_END_NAMESPACE
+
namespace qbs {
class Profile;
class Settings;
}
-void createClangClProfile(
- const QString &profileName, const QString &compilerFilePath, qbs::Settings *settings);
+void createClangClProfile(const QFileInfo &compiler, qbs::Settings *settings,
+ const QString &profileName);
void clangClProbe(qbs::Settings *settings, QList<qbs::Profile> &profiles);
-#endif // CLANGCLPROBE_H
+#endif // Header guard
diff --git a/src/app/qbs-setup-toolchains/commandlineparser.h b/src/app/qbs-setup-toolchains/commandlineparser.h
index 9d5b0c246..0616f068e 100644
--- a/src/app/qbs-setup-toolchains/commandlineparser.h
+++ b/src/app/qbs-setup-toolchains/commandlineparser.h
@@ -36,6 +36,7 @@
** $QT_END_LICENSE$
**
****************************************************************************/
+
#ifndef QBS_SETUPTOOLCHAINS_COMMANDLINEPARSER_H
#define QBS_SETUPTOOLCHAINS_COMMANDLINEPARSER_H
@@ -75,4 +76,4 @@ private:
QString m_command;
};
-#endif // Include guard
+#endif // Header guard
diff --git a/src/app/qbs-setup-toolchains/gccprobe.cpp b/src/app/qbs-setup-toolchains/gccprobe.cpp
index 9dd31b41b..2f2a22465 100644
--- a/src/app/qbs-setup-toolchains/gccprobe.cpp
+++ b/src/app/qbs-setup-toolchains/gccprobe.cpp
@@ -169,10 +169,11 @@ static bool doesProfileTargetOS(const Profile &profile, const QString &os)
return Internal::contains(HostOsInfo::hostOSIdentifiers(), os.toStdString());
}
-Profile createGccProfile(const QString &compilerFilePath, Settings *settings,
+Profile createGccProfile(const QFileInfo &compiler, Settings *settings,
const QStringList &toolchainTypes,
const QString &profileName)
{
+ const auto compilerFilePath = compiler.absoluteFilePath();
const QString machineName = gccMachineName(compilerFilePath);
if (toolchainTypes.contains(QLatin1String("mingw"))) {
@@ -188,7 +189,7 @@ Profile createGccProfile(const QString &compilerFilePath, Settings *settings,
// Check whether auxiliary tools reside within the toolchain's install path.
// This might not be the case when using icecc or another compiler wrapper.
- const QString compilerDirPath = QFileInfo(compilerFilePath).absolutePath();
+ const QString compilerDirPath = compiler.absolutePath();
const ToolPathSetup toolPathSetup(
&profile, compilerDirPath,
profile.value(QStringLiteral("cpp.toolchainPrefix"))
diff --git a/src/app/qbs-setup-toolchains/gccprobe.h b/src/app/qbs-setup-toolchains/gccprobe.h
index c39507741..6ce5938d0 100644
--- a/src/app/qbs-setup-toolchains/gccprobe.h
+++ b/src/app/qbs-setup-toolchains/gccprobe.h
@@ -36,8 +36,9 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef GCCPROBE_H
-#define GCCPROBE_H
+
+#ifndef QBS_SETUPTOOLCHAINS_GCCPROBE_H
+#define QBS_SETUPTOOLCHAINS_GCCPROBE_H
#include <QtCore/qlist.h>
@@ -50,7 +51,7 @@ class Profile;
class Settings;
}
-qbs::Profile createGccProfile(const QString &compilerFilePath,
+qbs::Profile createGccProfile(const QFileInfo &compiler,
qbs::Settings *settings,
const QStringList &toolchainTypes,
const QString &profileName = QString());
diff --git a/src/app/qbs-setup-toolchains/iarewprobe.h b/src/app/qbs-setup-toolchains/iarewprobe.h
index b21049314..b604d6c6b 100644
--- a/src/app/qbs-setup-toolchains/iarewprobe.h
+++ b/src/app/qbs-setup-toolchains/iarewprobe.h
@@ -37,8 +37,8 @@
**
****************************************************************************/
-#ifndef IAREWPROBE_H
-#define IAREWPROBE_H
+#ifndef QBS_SETUPTOOLCHAINS_IAREWPROBE_H
+#define QBS_SETUPTOOLCHAINS_IAREWPROBE_H
#include <QtCore/qlist.h>
@@ -58,4 +58,4 @@ void createIarProfile(const QFileInfo &compiler, qbs::Settings *settings,
void iarProbe(qbs::Settings *settings, QList<qbs::Profile> &profiles);
-#endif // IAREWPROBE_H
+#endif // Header guard
diff --git a/src/app/qbs-setup-toolchains/keilprobe.h b/src/app/qbs-setup-toolchains/keilprobe.h
index 321909bda..c7e66ee24 100644
--- a/src/app/qbs-setup-toolchains/keilprobe.h
+++ b/src/app/qbs-setup-toolchains/keilprobe.h
@@ -37,8 +37,8 @@
**
****************************************************************************/
-#ifndef KEILPROBE_H
-#define KEILPROBE_H
+#ifndef QBS_SETUPTOOLCHAINS_KEILPROBE_H
+#define QBS_SETUPTOOLCHAINS_KEILPROBE_H
#include <QtCore/qlist.h>
@@ -58,4 +58,4 @@ void createKeilProfile(const QFileInfo &compiler, qbs::Settings *settings,
void keilProbe(qbs::Settings *settings, QList<qbs::Profile> &profiles);
-#endif // KEILPROBE_H
+#endif // Header guard
diff --git a/src/app/qbs-setup-toolchains/msvcprobe.cpp b/src/app/qbs-setup-toolchains/msvcprobe.cpp
index d0b60a7fe..c8108bfd2 100644
--- a/src/app/qbs-setup-toolchains/msvcprobe.cpp
+++ b/src/app/qbs-setup-toolchains/msvcprobe.cpp
@@ -464,9 +464,10 @@ void msvcProbe(Settings *settings, QList<Profile> &profiles)
}
}
-void createMsvcProfile(const QString &profileName, const QString &compilerFilePath,
- Settings *settings)
+void createMsvcProfile(const QFileInfo &compiler, Settings *settings,
+ const QString &profileName)
{
+ const auto compilerFilePath = compiler.absoluteFilePath();
MSVC msvc(compilerFilePath, MSVC::architectureFromClPath(compilerFilePath));
msvc.init();
QList<Profile> dummy;
diff --git a/src/app/qbs-setup-toolchains/msvcprobe.h b/src/app/qbs-setup-toolchains/msvcprobe.h
index 4fa2cde48..f63dd5dc8 100644
--- a/src/app/qbs-setup-toolchains/msvcprobe.h
+++ b/src/app/qbs-setup-toolchains/msvcprobe.h
@@ -37,13 +37,17 @@
**
****************************************************************************/
-#ifndef MSVCPROBE_H
-#define MSVCPROBE_H
+#ifndef QBS_SETUPTOOLCHAINS_MSVCPROBE_H
+#define QBS_SETUPTOOLCHAINS_MSVCPROBE_H
#include <QtCore/qlist.h>
#include <vector>
+QT_BEGIN_NAMESPACE
+class QFileInfo;
+QT_END_NAMESPACE
+
namespace qbs {
class Profile;
class Settings;
@@ -59,9 +63,9 @@ struct MSVCInstallInfo
std::vector<MSVCInstallInfo> installedMSVCs();
-void createMsvcProfile(const QString &profileName, const QString &compilerFilePath,
- qbs::Settings *settings);
+void createMsvcProfile(const QFileInfo &compiler, qbs::Settings *settings,
+ const QString &profileName);
void msvcProbe(qbs::Settings *settings, QList<qbs::Profile> &profiles);
-#endif // MSVCPROBE_H
+#endif // Header guard
diff --git a/src/app/qbs-setup-toolchains/probe.cpp b/src/app/qbs-setup-toolchains/probe.cpp
index 3ea28a9ab..d1b473e0a 100644
--- a/src/app/qbs-setup-toolchains/probe.cpp
+++ b/src/app/qbs-setup-toolchains/probe.cpp
@@ -151,11 +151,11 @@ void createProfile(const QString &profileName, const QString &toolchainType,
toolchainTypes = canonicalToolchain(toolchainType);
if (toolchainTypes.contains(QLatin1String("msvc")))
- createMsvcProfile(profileName, compiler.absoluteFilePath(), settings);
+ createMsvcProfile(compiler, settings, profileName);
else if (toolchainTypes.contains(QLatin1String("clang-cl")))
- createClangClProfile(profileName, compiler.absoluteFilePath(), settings);
+ createClangClProfile(compiler, settings, profileName);
else if (toolchainTypes.contains(QLatin1String("gcc")))
- createGccProfile(compiler.absoluteFilePath(), settings, toolchainTypes, profileName);
+ createGccProfile(compiler, settings, toolchainTypes, profileName);
else if (toolchainTypes.contains(QLatin1String("iar")))
createIarProfile(compiler, settings, profileName);
else if (toolchainTypes.contains(QLatin1String("keil")))
diff --git a/src/app/qbs-setup-toolchains/probe.h b/src/app/qbs-setup-toolchains/probe.h
index 1149b0f8c..3dfb3f103 100644
--- a/src/app/qbs-setup-toolchains/probe.h
+++ b/src/app/qbs-setup-toolchains/probe.h
@@ -36,8 +36,9 @@
** $QT_END_LICENSE$
**
****************************************************************************/
-#ifndef QBS_PROBE_H
-#define QBS_PROBE_H
+
+#ifndef QBS_SETUPTOOLCHAINS_PROBE_H
+#define QBS_SETUPTOOLCHAINS_PROBE_H
#include <tools/version.h>
diff --git a/src/app/qbs-setup-toolchains/sdccprobe.h b/src/app/qbs-setup-toolchains/sdccprobe.h
index 4fe5ca407..5fad90e96 100644
--- a/src/app/qbs-setup-toolchains/sdccprobe.h
+++ b/src/app/qbs-setup-toolchains/sdccprobe.h
@@ -37,8 +37,8 @@
**
****************************************************************************/
-#ifndef SDCCPROBE_H
-#define SDCCPROBE_H
+#ifndef QBS_SETUPTOOLCHAINS_SDCCPROBE_H
+#define QBS_SETUPTOOLCHAINS_SDCCPROBE_H
#include <QtCore/qlist.h>
@@ -58,4 +58,4 @@ void createSdccProfile(const QFileInfo &compiler, qbs::Settings *settings,
void sdccProbe(qbs::Settings *settings, QList<qbs::Profile> &profiles);
-#endif // SDCCPROBE_H
+#endif // Header guard
diff --git a/src/app/qbs-setup-toolchains/xcodeprobe.h b/src/app/qbs-setup-toolchains/xcodeprobe.h
index 11fc2bffa..ab501036b 100644
--- a/src/app/qbs-setup-toolchains/xcodeprobe.h
+++ b/src/app/qbs-setup-toolchains/xcodeprobe.h
@@ -37,8 +37,8 @@
**
****************************************************************************/
-#ifndef XCODEPROBE_H
-#define XCODEPROBE_H
+#ifndef QBS_SETUPTOOLCHAINS_XCODEPROBE_H
+#define QBS_SETUPTOOLCHAINS_XCODEPROBE_H
#include <QtCore/qlist.h>
@@ -49,4 +49,4 @@ class Settings;
void xcodeProbe(qbs::Settings *settings, QList<qbs::Profile> &profiles);
-#endif // XCODEPROBE_H
+#endif // Header guard