summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIvan Komissarov <abbapoh@gmail.com>2022-01-25 21:29:00 +0300
committerRaphaƫl Cotty <raphael.cotty@gmail.com>2022-02-04 11:59:27 +0000
commite0502b32c49d877a790b6f36ddc3f63e5d2f1bc2 (patch)
treea65f0e7c6df313631f75138b06d6d8090f8ea38b
parentcb3d7e862c69c59e3b0111e19ace157be07acb88 (diff)
downloadqbs-e0502b32c49d877a790b6f36ddc3f63e5d2f1bc2.tar.gz
Do not use std::string in HostOsInfo
We are not going away from Qt and converting QString to std::strgin and vice versa does not make any sense. Change-Id: I99c0067a4738566728c503fe39f0d0a945d4e977 Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r--src/app/qbs-setup-qt/setupqt.cpp2
-rw-r--r--src/app/qbs-setup-toolchains/clangclprobe.cpp2
-rw-r--r--src/app/qbs-setup-toolchains/gccprobe.cpp9
-rw-r--r--src/lib/corelib/jsextensions/host.cpp6
-rw-r--r--src/lib/corelib/jsextensions/utilitiesextension.cpp11
-rw-r--r--src/lib/corelib/language/moduleloader.cpp6
-rw-r--r--src/lib/corelib/tools/hostosinfo.h74
-rw-r--r--tests/auto/blackbox/tst_blackbox.cpp7
-rw-r--r--tests/auto/shared.h3
9 files changed, 58 insertions, 62 deletions
diff --git a/src/app/qbs-setup-qt/setupqt.cpp b/src/app/qbs-setup-qt/setupqt.cpp
index 3426e15df..08caec657 100644
--- a/src/app/qbs-setup-qt/setupqt.cpp
+++ b/src/app/qbs-setup-qt/setupqt.cpp
@@ -172,7 +172,7 @@ static QString platformFromDirName(const QString &dir)
return QStringLiteral("android");
if (dir == QLatin1String("Boot2Qt"))
return QStringLiteral("linux");
- return QString::fromStdString(HostOsInfo::hostOSIdentifier());
+ return HostOsInfo::hostOSIdentifier();
}
QtEnvironment SetupQt::fetchEnvironment(const QString &qmakePath)
diff --git a/src/app/qbs-setup-toolchains/clangclprobe.cpp b/src/app/qbs-setup-toolchains/clangclprobe.cpp
index 3643a828d..c9c5a428c 100644
--- a/src/app/qbs-setup-toolchains/clangclprobe.cpp
+++ b/src/app/qbs-setup-toolchains/clangclprobe.cpp
@@ -101,7 +101,7 @@ void createClangClProfile(const QFileInfo &compiler, Settings *settings,
compiler.filePath(), ConsoleLogger::instance());
if (clangCl.isEmpty())
return;
- const auto hostArch = QString::fromStdString(HostOsInfo::hostOSArchitecture());
+ const auto hostArch = HostOsInfo::hostOSArchitecture();
createProfileHelper(
settings, profileName, clangCl.toolchainInstallPath, clangCl.vcvarsallPath, hostArch);
}
diff --git a/src/app/qbs-setup-toolchains/gccprobe.cpp b/src/app/qbs-setup-toolchains/gccprobe.cpp
index bbe77bb02..dda8f2274 100644
--- a/src/app/qbs-setup-toolchains/gccprobe.cpp
+++ b/src/app/qbs-setup-toolchains/gccprobe.cpp
@@ -231,12 +231,9 @@ private:
static bool doesProfileTargetOS(const Profile &profile, const QString &os)
{
const auto target = profile.value(QStringLiteral("qbs.targetPlatform"));
- if (target.isValid()) {
- return Internal::contains(HostOsInfo::canonicalOSIdentifiers(
- target.toString().toStdString()),
- os.toStdString());
- }
- return Internal::contains(HostOsInfo::hostOSIdentifiers(), os.toStdString());
+ if (target.isValid())
+ return Internal::contains(HostOsInfo::canonicalOSIdentifiers(target.toString()), os);
+ return Internal::contains(HostOsInfo::hostOSIdentifiers(), os);
}
static QString buildProfileName(const QFileInfo &cfi)
diff --git a/src/lib/corelib/jsextensions/host.cpp b/src/lib/corelib/jsextensions/host.cpp
index dae786383..ebf302a82 100644
--- a/src/lib/corelib/jsextensions/host.cpp
+++ b/src/lib/corelib/jsextensions/host.cpp
@@ -71,7 +71,7 @@ static QStringList osList()
{
QStringList list;
for (const auto &s : HostOsInfo::canonicalOSIdentifiers(HostOsInfo::hostOSIdentifier()))
- list.push_back(QString::fromStdString(s));
+ list.push_back(s);
return list;
}
@@ -86,7 +86,7 @@ QScriptValue Host::js_architecture(QScriptContext *context, QScriptEngine *engin
Q_UNUSED(context);
Q_UNUSED(engine);
- return QString::fromStdString(HostOsInfo::hostOSArchitecture());
+ return HostOsInfo::hostOSArchitecture();
}
QScriptValue Host::js_os(QScriptContext *context, QScriptEngine *engine)
@@ -100,7 +100,7 @@ QScriptValue Host::js_platform(QScriptContext *context, QScriptEngine *engine)
{
Q_UNUSED(context);
Q_UNUSED(engine);
- return QString::fromStdString(HostOsInfo::hostOSIdentifier());
+ return HostOsInfo::hostOSIdentifier();
}
QScriptValue Host::js_osVersion(QScriptContext *context, QScriptEngine *engine)
diff --git a/src/lib/corelib/jsextensions/utilitiesextension.cpp b/src/lib/corelib/jsextensions/utilitiesextension.cpp
index 2d00b5991..19afc6ca9 100644
--- a/src/lib/corelib/jsextensions/utilitiesextension.cpp
+++ b/src/lib/corelib/jsextensions/utilitiesextension.cpp
@@ -144,9 +144,10 @@ QScriptValue UtilitiesExtension::js_canonicalPlatform(QScriptContext *context,
if (context->argumentCount() == 1 && value.isString()) {
return engine->toScriptValue([&value] {
- const auto ids = HostOsInfo::canonicalOSIdentifiers(value.toString().toStdString());
- return transformed<QStringList>(ids, [](const auto &s) {
- return QString::fromStdString(s); });
+ QStringList list;
+ for (const auto &s : HostOsInfo::canonicalOSIdentifiers(value.toString()))
+ list.push_back(s);
+ return list;
}());
}
@@ -567,7 +568,7 @@ QScriptValue UtilitiesExtension::js_clangClCompilerInfo(QScriptContext *context,
// to host architecture if none is present
QString arch = !context->argument(1).isNull() && !context->argument(1).isUndefined()
? context->argument(1).toString()
- : QString::fromStdString(HostOsInfo::hostOSArchitecture());
+ : HostOsInfo::hostOSArchitecture();
QString vcvarsallPath = context->argument(2).toString();
const QString compilerLanguage =
!context->argument(3).isNull() && !context->argument(3).isUndefined()
@@ -607,7 +608,7 @@ QScriptValue UtilitiesExtension::js_installedMSVCs(QScriptContext *context, QScr
}
const auto value0 = context->argument(0);
- const auto hostArch = QString::fromStdString(HostOsInfo::hostOSArchitecture());
+ const auto hostArch = HostOsInfo::hostOSArchitecture();
const auto preferredArch = !value0.isNull() && !value0.isUndefined()
? value0.toString()
: hostArch;
diff --git a/src/lib/corelib/language/moduleloader.cpp b/src/lib/corelib/language/moduleloader.cpp
index 57578ddb0..52381465a 100644
--- a/src/lib/corelib/language/moduleloader.cpp
+++ b/src/lib/corelib/language/moduleloader.cpp
@@ -3228,11 +3228,9 @@ Item::Module ModuleLoader::loadBaseModule(ProductContext *productContext, Item *
void ModuleLoader::setupBaseModulePrototype(Item *prototype)
{
prototype->setProperty(QStringLiteral("hostPlatform"),
- VariantValue::create(QString::fromStdString(
- HostOsInfo::hostOSIdentifier())));
+ VariantValue::create(HostOsInfo::hostOSIdentifier()));
prototype->setProperty(QStringLiteral("hostArchitecture"),
- VariantValue::create(QString::fromStdString(
- HostOsInfo::hostOSArchitecture())));
+ VariantValue::create(HostOsInfo::hostOSArchitecture()));
prototype->setProperty(QStringLiteral("libexecPath"),
VariantValue::create(m_parameters.libexecPath()));
diff --git a/src/lib/corelib/tools/hostosinfo.h b/src/lib/corelib/tools/hostosinfo.h
index cbb4f8a45..32817f731 100644
--- a/src/lib/corelib/tools/hostosinfo.h
+++ b/src/lib/corelib/tools/hostosinfo.h
@@ -73,10 +73,10 @@ public:
// Add more as needed.
enum HostOs { HostOsWindows, HostOsLinux, HostOsMacos, HostOsOtherUnix, HostOsOther };
- static inline std::string hostOSIdentifier();
- static inline std::string hostOSArchitecture();
- static inline std::vector<std::string> hostOSIdentifiers();
- static inline std::vector<std::string> canonicalOSIdentifiers(const std::string &os);
+ static inline QString hostOSIdentifier();
+ static inline QString hostOSArchitecture();
+ static inline std::vector<QString> hostOSIdentifiers();
+ static inline std::vector<QString> canonicalOSIdentifiers(const QString &os);
static inline HostOs hostOs();
static inline Version hostOsVersion() {
@@ -177,68 +177,68 @@ public:
}
};
-std::string HostOsInfo::hostOSIdentifier()
+QString HostOsInfo::hostOSIdentifier()
{
#if defined(__APPLE__)
- return "macos";
+ return QStringLiteral("macos");
#elif defined(WIN32) || defined(_WIN32) || defined(__WIN32__) || defined(__NT__)
- return "windows";
+ return QStringLiteral("windows");
#elif defined(_AIX)
- return "aix";
+ return QStringLiteral("aix");
#elif defined(hpux) || defined(__hpux)
- return "hpux";
+ return QStringLiteral("hpux");
#elif defined(__sun) || defined(sun)
- return "solaris";
+ return QStringLiteral("solaris");
#elif defined(__linux__) || defined(__linux)
- return "linux";
+ return QStringLiteral("linux");
#elif defined(__FreeBSD__) || defined(__DragonFly__) || defined(__FreeBSD_kernel__)
- return "freebsd";
+ return QStringLiteral("freebsd");
#elif defined(__NetBSD__)
- return "netbsd";
+ return QStringLiteral("netbsd");
#elif defined(__OpenBSD__)
- return "openbsd";
+ return QStringLiteral("openbsd");
#elif defined(__GNU__)
- return "hurd";
+ return QStringLiteral("hurd");
#elif defined(__HAIKU__)
- return "haiku";
+ return QStringLiteral("haiku");
#else
#warning "Qbs has not been ported to this OS - see http://qbs.io/"
- return "";
+ return {};
#endif
}
-std::string HostOsInfo::hostOSArchitecture()
+QString HostOsInfo::hostOSArchitecture()
{
const auto cpuArch = QSysInfo::currentCpuArchitecture();
if (cpuArch == QLatin1String("i386"))
- return "x86";
- return cpuArch.toStdString();
+ return QStringLiteral("x86");
+ return cpuArch;
}
-std::vector<std::string> HostOsInfo::hostOSIdentifiers()
+std::vector<QString> HostOsInfo::hostOSIdentifiers()
{
return canonicalOSIdentifiers(hostOSIdentifier());
}
-std::vector<std::string> HostOsInfo::canonicalOSIdentifiers(const std::string &name)
+std::vector<QString> HostOsInfo::canonicalOSIdentifiers(const QString &name)
{
- std::vector<std::string> list { name };
- if (contains({"ios-simulator"}, name))
- list << canonicalOSIdentifiers("ios");
- if (contains({"tvos-simulator"}, name))
- list << canonicalOSIdentifiers("tvos");
- if (contains({"watchos-simulator"}, name))
- list << canonicalOSIdentifiers("watchos");
- if (contains({"macos", "ios", "tvos", "watchos"}, name))
- list << canonicalOSIdentifiers("darwin");
- if (contains({"darwin", "freebsd", "netbsd", "openbsd"}, name))
- list << canonicalOSIdentifiers("bsd");
- if (contains({"android"}, name))
- list << canonicalOSIdentifiers("linux");
+ std::vector<QString> list { name };
+ if (contains({u"ios-simulator"}, name))
+ list << canonicalOSIdentifiers(QStringLiteral("ios"));
+ if (contains({u"tvos-simulator"}, name))
+ list << canonicalOSIdentifiers(QStringLiteral("tvos"));
+ if (contains({u"watchos-simulator"}, name))
+ list << canonicalOSIdentifiers(QStringLiteral("watchos"));
+ if (contains({u"macos", u"ios", u"tvos", u"watchos"}, name))
+ list << canonicalOSIdentifiers(QStringLiteral("darwin"));
+ if (contains({u"darwin", u"freebsd", u"netbsd", u"openbsd"}, name))
+ list << canonicalOSIdentifiers(QStringLiteral("bsd"));
+ if (contains({u"android"}, name))
+ list << canonicalOSIdentifiers(QStringLiteral("linux"));
// Note: recognized non-Unix platforms include: windows, haiku, vxworks
- if (contains({"bsd", "aix", "hpux", "solaris", "linux", "hurd", "qnx", "integrity"}, name))
- list << canonicalOSIdentifiers("unix");
+ if (contains({u"bsd", u"aix", u"hpux", u"solaris", u"linux", u"hurd", u"qnx", u"integrity"}, name))
+ list << canonicalOSIdentifiers(QStringLiteral("unix"));
return list;
}
diff --git a/tests/auto/blackbox/tst_blackbox.cpp b/tests/auto/blackbox/tst_blackbox.cpp
index 2846dd40b..7aa6607fd 100644
--- a/tests/auto/blackbox/tst_blackbox.cpp
+++ b/tests/auto/blackbox/tst_blackbox.cpp
@@ -4599,7 +4599,7 @@ void TestBlackbox::jsExtensionsHost()
HostOsInfo::hostOSArchitecture());
QStringList list;
for (const auto &s : HostOsInfo::canonicalOSIdentifiers(HostOsInfo::hostOSIdentifier()))
- list.push_back(QString::fromStdString(s));
+ list.push_back(s);
QCOMPARE(lines.at(i++).trimmed().constData(), "os: " + list.join(','));
QCOMPARE(lines.at(i++).trimmed().constData(), "platform: " + HostOsInfo::hostOSIdentifier());
QCOMPARE(lines.at(i++).trimmed().constData(), "osVersion: " +
@@ -8454,9 +8454,10 @@ void TestBlackbox::hostOsProperties()
QSKIP("Cannot run binaries in cross-compiled build");
QCOMPARE(runQbs(QStringLiteral("run")), 0);
QVERIFY2(m_qbsStdout.contains(
- ("HOST_ARCHITECTURE = " + HostOsInfo::hostOSArchitecture()).data()),
+ ("HOST_ARCHITECTURE = " + HostOsInfo::hostOSArchitecture().toUtf8()).data()),
m_qbsStdout.constData());
- QVERIFY2(m_qbsStdout.contains(("HOST_PLATFORM = " + HostOsInfo::hostOSIdentifier()).data()),
+ QVERIFY2(m_qbsStdout.contains(
+ ("HOST_PLATFORM = " + HostOsInfo::hostOSIdentifier().toUtf8()).data()),
m_qbsStdout.constData());
}
diff --git a/tests/auto/shared.h b/tests/auto/shared.h
index 94c22b47e..53ff364fb 100644
--- a/tests/auto/shared.h
+++ b/tests/auto/shared.h
@@ -351,8 +351,7 @@ inline qbs::Internal::HostOsInfo::HostOs targetOs()
const qbs::Profile buildProfile(profileName(), s.get());
const QString targetPlatform = buildProfile.value("qbs.targetPlatform").toString();
if (!targetPlatform.isEmpty()) {
- const std::vector<std::string> targetOS = qbs::Internal::HostOsInfo::canonicalOSIdentifiers(
- targetPlatform.toStdString());
+ const auto targetOS = qbs::Internal::HostOsInfo::canonicalOSIdentifiers(targetPlatform);
if (qbs::Internal::contains(targetOS, "windows"))
return qbs::Internal::HostOsInfo::HostOsWindows;
if (qbs::Internal::contains(targetOS, "linux"))