forked from qt-creator/qt-creator
CMakePM: Use parent environment for $env{macro} expansion
Now the code takes into consideration the parent environment for $env{macro} alongside the "environment" presets values. Task-number: QTCREATORBUG-24555 Change-Id: I644618b0a6f866fd65a4109ee63b1f5bfcd4164d Reviewed-by: Alessandro Portale <alessandro.portale@qt.io> Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
This commit is contained in:
@@ -99,13 +99,33 @@ static QString expandMacroEnv(const QString ¯oPrefix,
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static QHash<QString, QString> getEnvCombined(
|
||||||
|
const std::optional<QHash<QString, QString>> &optPresetEnv, const Utils::Environment &env)
|
||||||
|
{
|
||||||
|
QHash<QString, QString> result;
|
||||||
|
|
||||||
|
for (auto it = env.constBegin(); it != env.constEnd(); ++it) {
|
||||||
|
if (it.value().second)
|
||||||
|
result.insert(it.key().name, it.value().first);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!optPresetEnv)
|
||||||
|
return result;
|
||||||
|
|
||||||
|
QHash<QString, QString> presetEnv = optPresetEnv.value();
|
||||||
|
for (auto it = presetEnv.constKeyValueBegin(); it != presetEnv.constKeyValueEnd(); ++it) {
|
||||||
|
result[it->first] = it->second;
|
||||||
|
}
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
template<class PresetType>
|
template<class PresetType>
|
||||||
void expand(const PresetType &preset,
|
void expand(const PresetType &preset,
|
||||||
Utils::Environment &env,
|
Utils::Environment &env,
|
||||||
const Utils::FilePath &sourceDirectory)
|
const Utils::FilePath &sourceDirectory)
|
||||||
{
|
{
|
||||||
const QHash<QString, QString> presetEnv = preset.environment ? preset.environment.value()
|
const QHash<QString, QString> presetEnv = getEnvCombined(preset.environment, env);
|
||||||
: QHash<QString, QString>();
|
|
||||||
for (auto it = presetEnv.constKeyValueBegin(); it != presetEnv.constKeyValueEnd(); ++it) {
|
for (auto it = presetEnv.constKeyValueBegin(); it != presetEnv.constKeyValueEnd(); ++it) {
|
||||||
const QString key = it->first;
|
const QString key = it->first;
|
||||||
QString value = it->second;
|
QString value = it->second;
|
||||||
@@ -143,14 +163,15 @@ 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>();
|
||||||
|
|
||||||
for (auto it = presetEnv.constKeyValueBegin(); it != presetEnv.constKeyValueEnd(); ++it) {
|
for (auto it = presetEnv.constKeyValueBegin(); it != presetEnv.constKeyValueEnd(); ++it) {
|
||||||
const QString key = it->first;
|
const QString key = it->first;
|
||||||
QString value = it->second;
|
QString value = it->second;
|
||||||
|
|
||||||
expandAllButEnv(preset, sourceDirectory, value);
|
expandAllButEnv(preset, sourceDirectory, value);
|
||||||
value = expandMacroEnv("env", value, [presetEnv](const QString ¯oName) {
|
value = expandMacroEnv("env", value, [presetEnv](const QString ¯oName) {
|
||||||
|
if (presetEnv.contains(macroName))
|
||||||
return presetEnv.value(macroName);
|
return presetEnv.value(macroName);
|
||||||
|
return QString("${%1}").arg(macroName);
|
||||||
});
|
});
|
||||||
|
|
||||||
auto operation = Utils::EnvironmentItem::Operation::SetEnabled;
|
auto operation = Utils::EnvironmentItem::Operation::SetEnabled;
|
||||||
@@ -178,9 +199,7 @@ void expand(const PresetType &preset,
|
|||||||
{
|
{
|
||||||
expandAllButEnv(preset, sourceDirectory, value);
|
expandAllButEnv(preset, sourceDirectory, value);
|
||||||
|
|
||||||
const QHash<QString, QString> presetEnv = preset.environment ? preset.environment.value()
|
const QHash<QString, QString> presetEnv = getEnvCombined(preset.environment, env);
|
||||||
: QHash<QString, QString>();
|
|
||||||
|
|
||||||
value = expandMacroEnv("env", value, [presetEnv](const QString ¯oName) {
|
value = expandMacroEnv("env", value, [presetEnv](const QString ¯oName) {
|
||||||
return presetEnv.value(macroName);
|
return presetEnv.value(macroName);
|
||||||
});
|
});
|
||||||
|
@@ -75,8 +75,8 @@
|
|||||||
"VCToolsVersion": "14.29.30133",
|
"VCToolsVersion": "14.29.30133",
|
||||||
"WindowsSDKVersion" : "10.0.22000.0",
|
"WindowsSDKVersion" : "10.0.22000.0",
|
||||||
"VCArch": "x64",
|
"VCArch": "x64",
|
||||||
"VCToolsInstallDir": "$penv{ProgramFiles(x86)}/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/$env{VCToolsVersion}",
|
"VCToolsInstallDir": "$env{ProgramFiles(x86)}/Microsoft Visual Studio/2019/Professional/VC/Tools/MSVC/$env{VCToolsVersion}",
|
||||||
"WindowsSdkDir" : "$penv{ProgramFiles(x86)}/Windows Kits/10",
|
"WindowsSdkDir" : "$env{ProgramFiles(x86)}/Windows Kits/10",
|
||||||
"WindowsSdkIncVerDir": "$env{WindowsSdkDir}/Include/$env{WindowsSDKVersion}",
|
"WindowsSdkIncVerDir": "$env{WindowsSdkDir}/Include/$env{WindowsSDKVersion}",
|
||||||
"WindowsSdkLibVerDir": "$env{WindowsSdkDir}/Lib/$env{WindowsSDKVersion}",
|
"WindowsSdkLibVerDir": "$env{WindowsSdkDir}/Lib/$env{WindowsSDKVersion}",
|
||||||
|
|
||||||
@@ -90,7 +90,7 @@
|
|||||||
"displayName": "Linux GCC",
|
"displayName": "Linux GCC",
|
||||||
"generator": "Ninja",
|
"generator": "Ninja",
|
||||||
"binaryDir": "${sourceDir}/build-${presetName}",
|
"binaryDir": "${sourceDir}/build-${presetName}",
|
||||||
"toolchainFile" : "$penv{HOME}/Qt/6.3.2/gcc_64/lib/cmake/Qt6/qt.toolchain.cmake",
|
"toolchainFile" : "$env{HOME}/Qt/6.3.2/gcc_64/lib/cmake/Qt6/qt.toolchain.cmake",
|
||||||
"condition" : {
|
"condition" : {
|
||||||
"type": "equals",
|
"type": "equals",
|
||||||
"lhs": "${hostSystemName}",
|
"lhs": "${hostSystemName}",
|
||||||
|
Reference in New Issue
Block a user