forked from qt-creator/qt-creator
CMakePM: update CMakePresets macro replacement function
Moved to a handcrafted function instead of using regex. This way the Visual C++ Ninja only preset can be processed. Change-Id: I9b303ee1765db05544d81db7d3b8d9e5223f5f42 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
@@ -8,8 +8,6 @@
|
|||||||
#include <utils/filepath.h>
|
#include <utils/filepath.h>
|
||||||
#include <utils/hostosinfo.h>
|
#include <utils/hostosinfo.h>
|
||||||
|
|
||||||
#include <QRegularExpression>
|
|
||||||
|
|
||||||
namespace CMakeProjectManager::Internal::CMakePresets::Macros {
|
namespace CMakeProjectManager::Internal::CMakePresets::Macros {
|
||||||
|
|
||||||
QString getHostSystemName()
|
QString getHostSystemName()
|
||||||
@@ -61,6 +59,48 @@ void expandAllButEnv(const PresetsDetails::BuildPreset &preset,
|
|||||||
value.replace("${presetName}", preset.name);
|
value.replace("${presetName}", preset.name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString expandMacroEnv(const QString ¯oPrefix,
|
||||||
|
const QString &value,
|
||||||
|
const std::function<QString(const QString &)> &op)
|
||||||
|
{
|
||||||
|
const QString startToken = QString("$%1{").arg(macroPrefix);
|
||||||
|
const QString endToken = QString("}");
|
||||||
|
|
||||||
|
auto findMacro = [startToken,
|
||||||
|
endToken](const QString &str, qsizetype *pos, QString *ret) -> qsizetype {
|
||||||
|
forever {
|
||||||
|
qsizetype openPos = str.indexOf(startToken, *pos);
|
||||||
|
if (openPos < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
qsizetype varPos = openPos + startToken.length();
|
||||||
|
qsizetype endPos = str.indexOf(endToken, varPos + 1);
|
||||||
|
if (endPos < 0)
|
||||||
|
return 0;
|
||||||
|
|
||||||
|
*ret = str.mid(varPos, endPos - varPos);
|
||||||
|
*pos = openPos;
|
||||||
|
|
||||||
|
return endPos - openPos + endToken.length();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
QString result = value;
|
||||||
|
QString macroName;
|
||||||
|
|
||||||
|
bool done = true;
|
||||||
|
do {
|
||||||
|
done = true;
|
||||||
|
for (qsizetype pos = 0; int len = findMacro(result, &pos, ¯oName);) {
|
||||||
|
result.replace(pos, len, op(macroName));
|
||||||
|
pos += macroName.length();
|
||||||
|
done = false;
|
||||||
|
}
|
||||||
|
} while (!done);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
template<class PresetType>
|
template<class PresetType>
|
||||||
void expand(const PresetType &preset,
|
void expand(const PresetType &preset,
|
||||||
Utils::Environment &env,
|
Utils::Environment &env,
|
||||||
@@ -73,14 +113,9 @@ void expand(const PresetType &preset,
|
|||||||
QString value = it->second;
|
QString value = it->second;
|
||||||
|
|
||||||
expandAllButEnv(preset, sourceDirectory, value);
|
expandAllButEnv(preset, sourceDirectory, value);
|
||||||
|
value = expandMacroEnv("env", value, [presetEnv](const QString ¯oName) {
|
||||||
QRegularExpression envRegex(R"((\$env\{(\w+)\}))");
|
return presetEnv.value(macroName);
|
||||||
for (const QRegularExpressionMatch &match : envRegex.globalMatch(value)) {
|
});
|
||||||
if (match.captured(2) != key)
|
|
||||||
value.replace(match.captured(1), presetEnv.value(match.captured(2)));
|
|
||||||
else
|
|
||||||
value.replace(match.captured(1), "");
|
|
||||||
}
|
|
||||||
|
|
||||||
QString sep;
|
QString sep;
|
||||||
bool append = true;
|
bool append = true;
|
||||||
@@ -92,9 +127,9 @@ void expand(const PresetType &preset,
|
|||||||
value.replace("$penv{PATH}", "", Qt::CaseInsensitive);
|
value.replace("$penv{PATH}", "", Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRegularExpression penvRegex(R"((\$penv\{(\w+)\}))");
|
value = expandMacroEnv("penv", value, [env](const QString ¯oName) {
|
||||||
for (const QRegularExpressionMatch &match : penvRegex.globalMatch(value))
|
return env.value(macroName);
|
||||||
value.replace(match.captured(1), env.value(match.captured(2)));
|
});
|
||||||
|
|
||||||
if (append)
|
if (append)
|
||||||
env.appendOrSet(key, value, sep);
|
env.appendOrSet(key, value, sep);
|
||||||
@@ -116,14 +151,9 @@ void expand(const PresetType &preset,
|
|||||||
QString value = it->second;
|
QString value = it->second;
|
||||||
|
|
||||||
expandAllButEnv(preset, sourceDirectory, value);
|
expandAllButEnv(preset, sourceDirectory, value);
|
||||||
|
value = expandMacroEnv("env", value, [presetEnv](const QString ¯oName) {
|
||||||
QRegularExpression envRegex(R"((\$env\{(\w+)\}))");
|
return presetEnv.value(macroName);
|
||||||
for (const QRegularExpressionMatch &match : envRegex.globalMatch(value)) {
|
});
|
||||||
if (match.captured(2) != key)
|
|
||||||
value.replace(match.captured(1), presetEnv.value(match.captured(2)));
|
|
||||||
else
|
|
||||||
value.replace(match.captured(1), "");
|
|
||||||
}
|
|
||||||
|
|
||||||
auto operation = Utils::EnvironmentItem::Operation::SetEnabled;
|
auto operation = Utils::EnvironmentItem::Operation::SetEnabled;
|
||||||
if (key.compare("PATH", Qt::CaseInsensitive) == 0) {
|
if (key.compare("PATH", Qt::CaseInsensitive) == 0) {
|
||||||
@@ -134,9 +164,9 @@ void expand(const PresetType &preset,
|
|||||||
value.replace("$penv{PATH}", "", Qt::CaseInsensitive);
|
value.replace("$penv{PATH}", "", Qt::CaseInsensitive);
|
||||||
}
|
}
|
||||||
|
|
||||||
QRegularExpression penvRegex(R"((\$penv\{(\w+)\}))");
|
value = expandMacroEnv("penv", value, [](const QString ¯oName) {
|
||||||
for (const QRegularExpressionMatch &match : penvRegex.globalMatch(value))
|
return QString("${%1}").arg(macroName);
|
||||||
value.replace(match.captured(1), QString("${%1}").arg(match.captured(2)));
|
});
|
||||||
|
|
||||||
envItems.emplace_back(Utils::EnvironmentItem(key, value, operation));
|
envItems.emplace_back(Utils::EnvironmentItem(key, value, operation));
|
||||||
}
|
}
|
||||||
@@ -153,13 +183,13 @@ void expand(const PresetType &preset,
|
|||||||
const QHash<QString, QString> presetEnv = preset.environment ? preset.environment.value()
|
const QHash<QString, QString> presetEnv = preset.environment ? preset.environment.value()
|
||||||
: QHash<QString, QString>();
|
: QHash<QString, QString>();
|
||||||
|
|
||||||
QRegularExpression envRegex(R"((\$env\{(\w+)\}))");
|
value = expandMacroEnv("env", value, [presetEnv](const QString ¯oName) {
|
||||||
for (const QRegularExpressionMatch &match : envRegex.globalMatch(value))
|
return presetEnv.value(macroName);
|
||||||
value.replace(match.captured(1), presetEnv.value(match.captured(2)));
|
});
|
||||||
|
|
||||||
QRegularExpression penvRegex(R"((\$penv\{(\w+)\}))");
|
value = expandMacroEnv("penv", value, [env](const QString ¯oName) {
|
||||||
for (const QRegularExpressionMatch &match : penvRegex.globalMatch(value))
|
return env.value(macroName);
|
||||||
value.replace(match.captured(1), env.value(match.captured(2)));
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateToolchainFile(
|
void updateToolchainFile(
|
||||||
@@ -261,7 +291,6 @@ bool evaluatePresetCondition(const PresetType &preset, const Utils::FilePath &so
|
|||||||
return condition.evaluate();
|
return condition.evaluate();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Expand for PresetsDetails::ConfigurePreset
|
// Expand for PresetsDetails::ConfigurePreset
|
||||||
template void expand<PresetsDetails::ConfigurePreset>(const PresetsDetails::ConfigurePreset &preset,
|
template void expand<PresetsDetails::ConfigurePreset>(const PresetsDetails::ConfigurePreset &preset,
|
||||||
Utils::Environment &env,
|
Utils::Environment &env,
|
||||||
|
@@ -54,6 +54,34 @@
|
|||||||
"HOST_SYSTEM_NAME": "Windows"
|
"HOST_SYSTEM_NAME": "Windows"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"name": "visualc-ninja",
|
||||||
|
"displayName": "Visual C++ 2019 x64 Ninja",
|
||||||
|
"generator": "Ninja",
|
||||||
|
"binaryDir": "${sourceDir}/build-${presetName}",
|
||||||
|
"toolchainFile" : "c:/Qt/6.3.2/msvc2019_64/lib/cmake/Qt6/qt.toolchain.cmake",
|
||||||
|
"cacheVariables": {
|
||||||
|
"CMAKE_BUILD_TYPE": "Release"
|
||||||
|
},
|
||||||
|
"condition": {
|
||||||
|
"type": "equals",
|
||||||
|
"lhs": "${hostSystemName}",
|
||||||
|
"rhs": "Windows"
|
||||||
|
},
|
||||||
|
"environment" : {
|
||||||
|
"VCToolsVersion": "14.29.30133",
|
||||||
|
"WindowsSDKVersion" : "10.0.22000.0",
|
||||||
|
"VCArch": "x64",
|
||||||
|
"VCToolsInstallDir": "$penv{ProgramFiles(x86)}/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/$env{VCToolsVersion}",
|
||||||
|
"WindowsSdkDir" : "$penv{ProgramFiles(x86)}/Windows Kits/10",
|
||||||
|
"WindowsSdkIncVerDir": "$env{WindowsSdkDir}/Include/$env{WindowsSDKVersion}",
|
||||||
|
"WindowsSdkLibVerDir": "$env{WindowsSdkDir}/Lib/$env{WindowsSDKVersion}",
|
||||||
|
|
||||||
|
"INCLUDE": "$env{VCToolsInstallDir}/ATLMFC/include;$env{VCToolsInstallDir}/include;$env{WindowsSdkIncVerDir}/ucrt;$env{WindowsSdkIncVerDir}/shared;$env{WindowsSdkIncVerDir}/um;$env{WindowsSdkIncVerDir}/winrt;$env{WindowsSdkIncVerDir}/cppwinrt",
|
||||||
|
"LIB": "$env{VCToolsInstallDir}/ATLMFC/lib/$env{VCArch};$env{VCToolsInstallDir}/lib/$env{VCArch};$env{WindowsSdkLibVerDir}/ucrt/$env{VCArch};$env{WindowsSdkLibVerDir}/um/$env{VCArch}",
|
||||||
|
"PATH": "$env{VCToolsInstallDir}/bin/HostX64/$env{VCArch};$env{WindowsSdkDir}/bin/$env{WindowsSDKVersion}/$env{VCArch};$penv{PATH}"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"name": "linux-gcc",
|
"name": "linux-gcc",
|
||||||
"displayName": "Linux GCC",
|
"displayName": "Linux GCC",
|
||||||
@@ -95,6 +123,10 @@
|
|||||||
"name": "visualc-relwithdebinfo",
|
"name": "visualc-relwithdebinfo",
|
||||||
"inherits": "visualc-debug",
|
"inherits": "visualc-debug",
|
||||||
"configuration": "RelWithDebInfo"
|
"configuration": "RelWithDebInfo"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "visualc-ninja",
|
||||||
|
"configurePreset": "visualc-ninja"
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@@ -13,8 +13,36 @@
|
|||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string>MainWindow</string>
|
<string>MainWindow</string>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="centralwidget"/>
|
<widget class="QWidget" name="centralwidget">
|
||||||
<widget class="QMenuBar" name="menubar"/>
|
<widget class="QLabel" name="label">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>140</x>
|
||||||
|
<y>200</y>
|
||||||
|
<width>441</width>
|
||||||
|
<height>81</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
<property name="font">
|
||||||
|
<font>
|
||||||
|
<pointsize>22</pointsize>
|
||||||
|
</font>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>CMakePresets are cool!</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</widget>
|
||||||
|
<widget class="QMenuBar" name="menubar">
|
||||||
|
<property name="geometry">
|
||||||
|
<rect>
|
||||||
|
<x>0</x>
|
||||||
|
<y>0</y>
|
||||||
|
<width>800</width>
|
||||||
|
<height>22</height>
|
||||||
|
</rect>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
<widget class="QStatusBar" name="statusbar"/>
|
<widget class="QStatusBar" name="statusbar"/>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
Reference in New Issue
Block a user