Skip to content

Commit

Permalink
Use QStringBuilder
Browse files Browse the repository at this point in the history
Change-Id: Id09db3b28beb1dbe718f1bb00eba1b05c33445bc
Reviewed-by: Christian Kandeler <[email protected]>
  • Loading branch information
orgads committed Dec 25, 2024
1 parent a4806a6 commit 95f859c
Show file tree
Hide file tree
Showing 18 changed files with 86 additions and 66 deletions.
5 changes: 4 additions & 1 deletion cmake/QbsBuildConfig.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ set(DEFAULT_DEFINES
QT_WARN_DEPRECATED_BEFORE=0x060700
QT_WARN_DEPRECATED_UP_TO=0x060700
QT_NO_JAVA_STYLE_ITERATORS
QT_USE_QSTRINGBUILDER
)
if(WIN32)
list(APPEND DEFAULT_DEFINES UNICODE _UNICODE _SCL_SECURE_NO_WARNINGS)
Expand Down Expand Up @@ -244,8 +245,10 @@ function(add_qbs_test test_name)
"QBS_TEST_SUITE_NAME=\"${suite_name}\""
"SRCDIR=\"${CMAKE_CURRENT_SOURCE_DIR}\""
)
set(TEST_DEFINES ${DEFAULT_DEFINES})
list(REMOVE_ITEM TEST_DEFINES QT_USE_QSTRINGBUILDER)
target_compile_definitions(
${target_name} PRIVATE ${_arg_DEFINES} ${DEFAULT_DEFINES} PUBLIC ${_arg_PUBLIC_DEFINES})
${target_name} PRIVATE ${_arg_DEFINES} ${TEST_DEFINES} PUBLIC ${_arg_PUBLIC_DEFINES})
target_include_directories(
${target_name}
PRIVATE ${_arg_INCLUDES} "${CMAKE_CURRENT_SOURCE_DIR}/../../../src"
Expand Down
1 change: 1 addition & 0 deletions qbs-resources/imports/QbsProduct.qbs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Product {
"QT_NO_CAST_FROM_BYTEARRAY",
"QT_NO_JAVA_STYLE_ITERATORS",
"QT_NO_PROCESS_COMBINED_ARGUMENT_START",
"QT_USE_QSTRINGBUILDER",
"QT_DISABLE_DEPRECATED_BEFORE=0x050f00",
"QT_DISABLE_DEPRECATED_UP_TO=0x050f00",
"QT_WARN_DEPRECATED_BEFORE=0x060700",
Expand Down
3 changes: 1 addition & 2 deletions src/app/qbs-setup-toolchains/clangclprobe.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,7 @@ void clangClProbe(Settings *settings, std::vector<Profile> &profiles)
const QString suffix = index == 0 ? QString() : QStringLiteral("-%1").arg(index);
qbs::Internal::transform(
architectures, profiles, [settings, clangCl, suffix](const auto &arch) {
const auto profileName = QStringLiteral("clang-cl") + suffix
+ QStringLiteral("-%1").arg(arch);
const auto profileName = QStringLiteral("clang-cl%1-%2").arg(suffix, arch);
return createProfileHelper(
settings,
profileName,
Expand Down
7 changes: 4 additions & 3 deletions src/lib/corelib/generators/generator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,10 @@ const GeneratableProject ProjectGenerator::project() const
QFileInfo ProjectGenerator::qbsExecutableFilePath() const
{
const QString qbsInstallDir = QString::fromLocal8Bit(qgetenv("QBS_INSTALL_DIR"));
auto file = QFileInfo(Internal::HostOsInfo::appendExecutableSuffix(!qbsInstallDir.isEmpty()
? qbsInstallDir + QLatin1String("/bin/qbs")
: QCoreApplication::applicationDirPath() + QLatin1String("/qbs")));
auto file = QFileInfo(Internal::HostOsInfo::appendExecutableSuffix(
!qbsInstallDir.isEmpty()
? QString(qbsInstallDir + QStringLiteral("/bin/qbs"))
: QString(QCoreApplication::applicationDirPath() + QStringLiteral("/qbs"))));
QBS_CHECK(file.isAbsolute() && file.exists());
return file;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/corelib/loader/moduleproviderloader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -399,7 +399,7 @@ ModuleProviderLoader::EvaluationResult ModuleProviderLoader::evaluateModuleProvi
auto searchPaths = m_loaderState.evaluator().stringListValue(
providerItem, QStringLiteral("relativeSearchPaths"));
auto prependBaseDir = [&outputBaseDir](const auto &path) {
return outputBaseDir + QLatin1Char('/') + path;
return QString(outputBaseDir + QLatin1Char('/') + path);
};
std::transform(searchPaths.begin(), searchPaths.end(), searchPaths.begin(), prependBaseDir);
return {searchPaths, isEager};
Expand Down
7 changes: 4 additions & 3 deletions src/lib/corelib/loader/productscollector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -373,9 +373,10 @@ void ProductsCollector::Private::prepareProduct(ProjectContext &projectContext,
// and nothing else, thus providing us with the pure environment that we need to
// evaluate the product's exported properties in isolation in the project resolver.
Item * const importer = Item::create(&loaderState.itemPool(), ItemType::Product);
importer->setProperty(QStringLiteral("name"),
VariantValue::create(StringConstants::shadowProductPrefix()
+ productContext.name));
importer->setProperty(
QStringLiteral("name"),
VariantValue::create(
QString(StringConstants::shadowProductPrefix() + productContext.name)));
importer->setFile(productItem->file());
importer->setLocation(productItem->location());
importer->setScope(projectContext.scope);
Expand Down
4 changes: 3 additions & 1 deletion src/lib/corelib/tools/msvcinfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -698,7 +698,9 @@ void MSVC::determineCompilerVersion()

std::lock_guard<std::recursive_mutex> locker(envMutex);
const QByteArray origPath = qgetenv("PATH");
qputenv("PATH", environment.value(StringConstants::pathEnvVar()).toLatin1() + ';' + origPath);
QByteArray tempPath = environment.value(StringConstants::pathEnvVar()).toLatin1() + ';'
+ origPath;
qputenv("PATH", tempPath);
QByteArray versionStr = runProcess(
binPath + clExeSuffix(),
QStringList() << QStringLiteral("/nologo") << QStringLiteral("/EP")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,8 +349,7 @@ void ArmLinkerSettingsGroup::buildConfigPage(
// Add remainder configuration files to the "Extra options page".
if (!opts.configFilePaths.isEmpty()) {
for (QVariant &configPath : opts.configFilePaths)
configPath = QLatin1String("--config ")
+ configPath.toString();
configPath = QString(QStringLiteral("--config ") + configPath.toString());

m_extraOptions << opts.configFilePaths;
}
Expand Down Expand Up @@ -389,7 +388,7 @@ void ArmLinkerSettingsGroup::buildLibraryPage(
// "Extra options page", because IAR IDE
// has not other options to add this paths.
for (QVariant &libraryPath : opts.librarySearchPaths)
libraryPath = QLatin1String("-L ") + libraryPath.toString();
libraryPath = QString(QStringLiteral("-L ") + libraryPath.toString());

m_extraOptions << opts.librarySearchPaths;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ void AvrLinkerSettingsGroup::buildConfigPage(
// Add remainder configuration files to the "Extra options page".
if (!opts.configFilePaths.isEmpty()) {
for (QVariant &configPath : opts.configFilePaths)
configPath = QLatin1String("-f ") + configPath.toString();
configPath = QString(QStringLiteral("-f ") + configPath.toString());

m_extraOptions << opts.configFilePaths;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ void Mcs51LinkerSettingsGroup::buildConfigPage(
// Add remainder configuration files to the "Extra options page".
if (!opts.configFilePaths.isEmpty()) {
for (QVariant &configPath : opts.configFilePaths)
configPath = QLatin1String("-f ") + configPath.toString();
configPath = QString(QStringLiteral("-f ") + configPath.toString());

m_extraOptions << opts.configFilePaths;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ void Msp430LinkerSettingsGroup::buildConfigPage(
// Add remainder configuration files to the "Extra options page".
if (!opts.configFilePaths.isEmpty()) {
for (QVariant &configPath : opts.configFilePaths)
configPath = QLatin1String("-f ") + configPath.toString();
configPath = QString(QStringLiteral("-f ") + configPath.toString());

m_extraOptions << opts.configFilePaths;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -294,7 +294,7 @@ void Stm8LinkerSettingsGroup::buildConfigPage(
// Add remainder configuration files to the "Extra options page".
if (!opts.configFilePaths.isEmpty()) {
for (QVariant &configPath : opts.configFilePaths)
configPath = QLatin1String("--config ") + configPath.toString();
configPath = QString(QStringLiteral("--config ") + configPath.toString());

m_extraOptions << opts.configFilePaths;
}
Expand Down
4 changes: 2 additions & 2 deletions src/plugins/generator/keiluv/keiluvutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ QStringList staticLibraries(const PropertyMap &qbsProps)
QStringList dependencies(const std::vector<ProductData> &qbsProductDeps)
{
return Internal::transformed<QStringList>(qbsProductDeps, [](const auto &dep) {
const auto path = dep.buildDirectory() + QLatin1String("/obj/")
+ gen::utils::targetBinary(dep);
const QString path = dep.buildDirectory() + QStringLiteral("/obj/")
+ gen::utils::targetBinary(dep);
return QDir::toNativeSeparators(path);
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,9 @@ MSBuildQbsGenerateProject::MSBuildQbsGenerateProject(
QStringLiteral("Makefile"));
const auto params = Internal::shellQuote(project.commandLine(),
Internal::HostOsInfo::HostOsWindows);
group->appendProperty(QStringLiteral("NMakeBuildCommandLine"),
QStringLiteral("$(QbsGenerateCommandLine) ") + params);
group->appendProperty(
QStringLiteral("NMakeBuildCommandLine"),
QString(QStringLiteral("$(QbsGenerateCommandLine) ") + params));

const auto cppProps = new MSBuildImport(this);
cppProps->setProject(QStringLiteral("$(VCTargetsPath)\\Microsoft.Cpp.props"));
Expand Down
56 changes: 31 additions & 25 deletions src/plugins/generator/visualstudio/msbuildqbsproductproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,11 @@ void MSBuildQbsProductProject::addConfiguration(const GeneratableProject &projec
// General - General
// We need a trailing backslash for $(OutDir); See also the VS documentation:
// https://docs.microsoft.com/en-us/cpp/ide/common-macros-for-build-commands-and-properties
propertyGroup1->appendProperty(QStringLiteral("OutDir"), relativeTargetDir + QLatin1Char('\\'));
propertyGroup1->appendProperty(
QStringLiteral("OutDir"), QString(relativeTargetDir + QLatin1Char('\\')));
propertyGroup1->appendProperty(QStringLiteral("TargetName"), productData.targetName());
propertyGroup1->appendProperty(QStringLiteral("PlatformToolset"),
versionInfo().platformToolsetVersion());
propertyGroup1->appendProperty(
QStringLiteral("PlatformToolset"), versionInfo().platformToolsetVersion());
propertyGroup1->appendProperty(QStringLiteral("ConfigurationType"), QStringLiteral("Makefile"));

// VS possible values: Unicode|MultiByte|NotSet
Expand Down Expand Up @@ -219,16 +220,19 @@ void MSBuildQbsProductProject::addConfiguration(const GeneratableProject &projec

// NMake - General
// Skip configuration name, that's handled in qbs-shared.props
const auto params = Internal::shellQuote(buildConfigurationCommandLine.mid(1),
Internal::HostOsInfo::HostOsWindows);
propertyGroup1->appendProperty(QStringLiteral("NMakeBuildCommandLine"),
QStringLiteral("$(QbsBuildCommandLine) ") + params);
propertyGroup1->appendProperty(QStringLiteral("NMakeReBuildCommandLine"),
QStringLiteral("$(QbsReBuildCommandLine) ") + params);
propertyGroup1->appendProperty(QStringLiteral("NMakeCleanCommandLine"),
QStringLiteral("$(QbsCleanCommandLine) ") + params);
propertyGroup1->appendProperty(QStringLiteral("NMakeOutput"),
QStringLiteral("$(OutDir)$(TargetName)$(TargetExt)"));
const auto params = Internal::shellQuote(
buildConfigurationCommandLine.mid(1), Internal::HostOsInfo::HostOsWindows);
propertyGroup1->appendProperty(
QStringLiteral("NMakeBuildCommandLine"),
QString(QStringLiteral("$(QbsBuildCommandLine) ") + params));
propertyGroup1->appendProperty(
QStringLiteral("NMakeReBuildCommandLine"),
QString(QStringLiteral("$(QbsReBuildCommandLine) ") + params));
propertyGroup1->appendProperty(
QStringLiteral("NMakeCleanCommandLine"),
QString(QStringLiteral("$(QbsCleanCommandLine) ") + params));
propertyGroup1->appendProperty(
QStringLiteral("NMakeOutput"), QStringLiteral("$(OutDir)$(TargetName)$(TargetExt)"));

// NMake - IntelliSense
propertyGroup1->appendProperty(QStringLiteral("NMakePreprocessorDefinitions"),
Expand Down Expand Up @@ -278,10 +282,9 @@ void MSBuildQbsProductProject::addItemDefGroup(const Project &project,
const auto compile = new MSBuildClCompile(itemDefGroup);

// C++ - General
compile->appendProperty(QStringLiteral("AdditionalIncludeDirectories"),
includePaths.join(sep)
+ sep
+ QStringLiteral("%(AdditionalIncludeDirectories)"));
compile->appendProperty(
QStringLiteral("AdditionalIncludeDirectories"),
QString(includePaths.join(sep) + sep + QStringLiteral("%(AdditionalIncludeDirectories)")));
if (warningLevel == QStringLiteral("none"))
compile->appendProperty(QStringLiteral("WarningLevel"),
QStringLiteral("TurnOffAllWarnings"));
Expand All @@ -299,10 +302,9 @@ void MSBuildQbsProductProject::addItemDefGroup(const Project &project,
: QStringLiteral("MaxSpeed"));

// C++ - Preprocessor
compile->appendProperty(QStringLiteral("PreprocessorDefinitions"),
cppDefines.join(sep)
+ sep
+ QStringLiteral("%(PreprocessorDefinitions)"));
compile->appendProperty(
QStringLiteral("PreprocessorDefinitions"),
QString(cppDefines.join(sep) + sep + QStringLiteral("%(PreprocessorDefinitions)")));

// C++ - Code Generation
compile->appendProperty(QStringLiteral("RuntimeLibrary"), debugBuild
Expand All @@ -317,10 +319,14 @@ void MSBuildQbsProductProject::addItemDefGroup(const Project &project,
QStringLiteral("libraryPaths")).join(sep));

// Linker - Input
link->appendProperty(QStringLiteral("AdditionalDependencies"),
properties.getModulePropertiesAsStringList(QStringLiteral("cpp"),
QStringLiteral("staticLibraries")).join(sep)
+ sep + QStringLiteral("%(AdditionalDependencies)"));
link->appendProperty(
QStringLiteral("AdditionalDependencies"),
QString(
properties
.getModulePropertiesAsStringList(
QStringLiteral("cpp"), QStringLiteral("staticLibraries"))
.join(sep)
+ sep + QStringLiteral("%(AdditionalDependencies)")));

// Linker - Debugging
link->appendProperty(QStringLiteral("GenerateDebugInformation"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,18 +112,19 @@ MSBuildSharedSolutionPropertiesProject::MSBuildSharedSolutionPropertiesProject(
group->setLabel(QStringLiteral("UserMacros"));

// Order's important here... a variable must be listed before one that uses it
group->appendProperty(QStringLiteral("QbsExecutablePath"),
QStringLiteral("$(QbsExecutableDir)") + qbsExecutable.fileName());
group->appendProperty(
QStringLiteral("QbsExecutablePath"),
QString(QStringLiteral("$(QbsExecutableDir)") + qbsExecutable.fileName()));
if (!project.installOptions.installRoot().isEmpty()) {
group->appendProperty(QStringLiteral("QbsInstallRoot"),
Internal::PathUtils::toNativeSeparators(
project.installOptions.installRoot(),
Internal::HostOsInfo::HostOsWindows));
group->appendProperty(
QStringLiteral("QbsInstallRoot"),
Internal::PathUtils::toNativeSeparators(
project.installOptions.installRoot(), Internal::HostOsInfo::HostOsWindows));
}

group->appendProperty(QStringLiteral("QbsProjectFile"),
QStringLiteral("$(QbsProjectDir)")
+ project.filePath().fileName());
group->appendProperty(
QStringLiteral("QbsProjectFile"),
QString(QStringLiteral("$(QbsProjectDir)") + project.filePath().fileName()));

// Trailing '.' is not a typo. It prevents the trailing slash from combining with the closing
// quote to form an escape sequence. Unfortunately, Visual Studio expands variables *before*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,17 +52,23 @@ MSBuildSolutionPropertiesProject::MSBuildSolutionPropertiesProject(

static const auto win = Internal::HostOsInfo::HostOsWindows;

group->appendProperty(QStringLiteral("QbsExecutableDir"),
Internal::PathUtils::toNativeSeparators(qbsExecutable.path(), win)
+ Internal::HostOsInfo::pathSeparator(win));
group->appendProperty(QStringLiteral("QbsProjectDir"),
Internal::PathUtils::toNativeSeparators(project.filePath().path(), win)
+ Internal::HostOsInfo::pathSeparator(win));
group->appendProperty(
QStringLiteral("QbsExecutableDir"),
QString(
Internal::PathUtils::toNativeSeparators(qbsExecutable.path(), win)
+ Internal::HostOsInfo::pathSeparator(win)));
group->appendProperty(
QStringLiteral("QbsProjectDir"),
QString(
Internal::PathUtils::toNativeSeparators(project.filePath().path(), win)
+ Internal::HostOsInfo::pathSeparator(win)));

if (!qbsSettingsDir.isEmpty()) {
group->appendProperty(QStringLiteral("QbsSettingsDir"),
Internal::PathUtils::toNativeSeparators(qbsSettingsDir, win)
+ Internal::HostOsInfo::pathSeparator(win) + QLatin1Char('.'));
group->appendProperty(
QStringLiteral("QbsSettingsDir"),
QString(
Internal::PathUtils::toNativeSeparators(qbsSettingsDir, win)
+ Internal::HostOsInfo::pathSeparator(win) + QLatin1Char('.')));
}
}

Expand Down
2 changes: 1 addition & 1 deletion tests/benchmarker/valgrindrunner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ qint64 ValgrindRunner::runMassif(const QString &qbsCommand, const QString &build
throw Exception(exceptionStringPattern.arg("No peak marker found"));
while (!buffer.atEnd()) {
const QByteArray line = buffer.readLine().simplified();
if (!line.startsWith(peakSnapshot + ' '))
if (!line.startsWith(QByteArray(peakSnapshot + ' ')))
continue;
const QList<QByteArray> entries = line.split(' ');
if (entries.size() != 6) {
Expand Down

0 comments on commit 95f859c

Please sign in to comment.