forked from qt-creator/qt-creator
CMakePM: Use Utils::Environment for Presets environment
Utils::Environment takes care of the case insesitivity of the key of environment variables on Windows. Change-Id: I624340d30c6b170b5d0a86791f26a4841a0b2fb7 Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
@@ -99,22 +99,17 @@ static QString expandMacroEnv(const QString ¯oPrefix,
|
||||
return result;
|
||||
}
|
||||
|
||||
static QHash<QString, QString> getEnvCombined(
|
||||
const std::optional<QHash<QString, QString>> &optPresetEnv, const Utils::Environment &env)
|
||||
static Utils::Environment getEnvCombined(const std::optional<Utils::Environment> &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);
|
||||
}
|
||||
Utils::Environment result = env;
|
||||
|
||||
if (!optPresetEnv)
|
||||
return result;
|
||||
|
||||
QHash<QString, QString> presetEnv = optPresetEnv.value();
|
||||
for (auto it = presetEnv.constKeyValueBegin(); it != presetEnv.constKeyValueEnd(); ++it) {
|
||||
result[it->first] = it->second;
|
||||
Utils::Environment presetEnv = optPresetEnv.value();
|
||||
for (auto it = presetEnv.constBegin(); it != presetEnv.constEnd(); ++it) {
|
||||
result.set(it.key().name, it.value().first);
|
||||
}
|
||||
|
||||
return result;
|
||||
@@ -125,10 +120,10 @@ void expand(const PresetType &preset,
|
||||
Utils::Environment &env,
|
||||
const Utils::FilePath &sourceDirectory)
|
||||
{
|
||||
const QHash<QString, QString> presetEnv = getEnvCombined(preset.environment, env);
|
||||
for (auto it = presetEnv.constKeyValueBegin(); it != presetEnv.constKeyValueEnd(); ++it) {
|
||||
const QString key = it->first;
|
||||
QString value = it->second;
|
||||
const Utils::Environment presetEnv = getEnvCombined(preset.environment, env);
|
||||
for (auto it = presetEnv.constBegin(); it != presetEnv.constEnd(); ++it) {
|
||||
const QString key = it.key().name;
|
||||
QString value = it.value().first;
|
||||
|
||||
expandAllButEnv(preset, sourceDirectory, value);
|
||||
value = expandMacroEnv("env", value, [presetEnv](const QString ¯oName) {
|
||||
@@ -161,15 +156,15 @@ void expand(const PresetType &preset,
|
||||
Utils::EnvironmentItems &envItems,
|
||||
const Utils::FilePath &sourceDirectory)
|
||||
{
|
||||
const QHash<QString, QString> presetEnv = preset.environment ? preset.environment.value()
|
||||
: QHash<QString, QString>();
|
||||
for (auto it = presetEnv.constKeyValueBegin(); it != presetEnv.constKeyValueEnd(); ++it) {
|
||||
const QString key = it->first;
|
||||
QString value = it->second;
|
||||
const Utils::Environment presetEnv = preset.environment ? preset.environment.value()
|
||||
: Utils::Environment();
|
||||
for (auto it = presetEnv.constBegin(); it != presetEnv.constEnd(); ++it) {
|
||||
const QString key = it.key().name;
|
||||
QString value = it.value().first;
|
||||
|
||||
expandAllButEnv(preset, sourceDirectory, value);
|
||||
value = expandMacroEnv("env", value, [presetEnv](const QString ¯oName) {
|
||||
if (presetEnv.contains(macroName))
|
||||
if (presetEnv.hasKey(macroName))
|
||||
return presetEnv.value(macroName);
|
||||
return QString("${%1}").arg(macroName);
|
||||
});
|
||||
@@ -199,7 +194,7 @@ void expand(const PresetType &preset,
|
||||
{
|
||||
expandAllButEnv(preset, sourceDirectory, value);
|
||||
|
||||
const QHash<QString, QString> presetEnv = getEnvCombined(preset.environment, env);
|
||||
const Utils::Environment presetEnv = getEnvCombined(preset.environment, env);
|
||||
value = expandMacroEnv("env", value, [presetEnv](const QString ¯oName) {
|
||||
return presetEnv.value(macroName);
|
||||
});
|
||||
|
@@ -208,10 +208,10 @@ bool parseConfigurePresets(const QJsonValue &jsonValue,
|
||||
const QJsonObject environmentObj = object.value("environment").toObject();
|
||||
for (const QString &envKey : environmentObj.keys()) {
|
||||
if (!preset.environment)
|
||||
preset.environment = QHash<QString, QString>();
|
||||
preset.environment = Utils::Environment();
|
||||
|
||||
QJsonValue envValue = environmentObj.value(envKey);
|
||||
preset.environment.value().insert(envKey, envValue.toString());
|
||||
preset.environment.value().set(envKey, envValue.toString());
|
||||
}
|
||||
|
||||
const QJsonObject warningsObj = object.value("warnings").toObject();
|
||||
@@ -335,10 +335,10 @@ bool parseBuildPresets(const QJsonValue &jsonValue,
|
||||
const QJsonObject environmentObj = object.value("environment").toObject();
|
||||
for (const QString &envKey : environmentObj.keys()) {
|
||||
if (!preset.environment)
|
||||
preset.environment = QHash<QString, QString>();
|
||||
preset.environment = Utils::Environment();
|
||||
|
||||
QJsonValue envValue = environmentObj.value(envKey);
|
||||
preset.environment.value().insert(envKey, envValue.toString());
|
||||
preset.environment.value().set(envKey, envValue.toString());
|
||||
}
|
||||
|
||||
if (object.contains("configurePreset"))
|
||||
@@ -452,6 +452,16 @@ static QHash<QString, QString> merge(const QHash<QString, QString> &first,
|
||||
return result;
|
||||
}
|
||||
|
||||
static Utils::Environment merge(const Utils::Environment &first, const Utils::Environment &second)
|
||||
{
|
||||
Utils::Environment result = first;
|
||||
for (auto it = second.constBegin(); it != second.constEnd(); ++it) {
|
||||
result.set(it.key().name, it.value().first);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static CMakeConfig merge(const CMakeConfig &first, const CMakeConfig &second)
|
||||
{
|
||||
return Utils::setUnionMerge<CMakeConfig>(
|
||||
|
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "cmakeconfigitem.h"
|
||||
|
||||
#include <utils/environment.h>
|
||||
#include <utils/filepath.h>
|
||||
|
||||
#include <QHash>
|
||||
@@ -103,7 +104,7 @@ public:
|
||||
std::optional<QString> installDir;
|
||||
std::optional<QString> cmakeExecutable;
|
||||
std::optional<CMakeConfig> cacheVariables;
|
||||
std::optional<QHash<QString, QString>> environment;
|
||||
std::optional<Utils::Environment> environment;
|
||||
std::optional<Warnings> warnings;
|
||||
std::optional<Errors> errors;
|
||||
std::optional<Debug> debug;
|
||||
@@ -120,7 +121,7 @@ public:
|
||||
std::optional<QHash<QString, QString>> vendor;
|
||||
std::optional<QString> displayName;
|
||||
std::optional<QString> description;
|
||||
std::optional<QHash<QString, QString>> environment;
|
||||
std::optional<Utils::Environment> environment;
|
||||
std::optional<QString> configurePreset;
|
||||
std::optional<bool> inheritConfigureEnvironment = true;
|
||||
std::optional<int> jobs;
|
||||
|
@@ -12,7 +12,7 @@
|
||||
"generator": "Ninja",
|
||||
"installDir": "../inst-${presetName}",
|
||||
"cacheVariables": {
|
||||
"CMAKE_PREFIX_PATH": "$env{SystemDrive}/Qt/6.3.2/mingw_64"
|
||||
"CMAKE_PREFIX_PATH": "$env{SYSTEMDRIVE}/Qt/6.3.2/mingw_64"
|
||||
},
|
||||
"condition": {
|
||||
"type": "equals",
|
||||
@@ -20,7 +20,7 @@
|
||||
"rhs": "Windows"
|
||||
},
|
||||
"environment": {
|
||||
"PATH": "$env{SystemDrive}/Qt/Tools/mingw1120_64/bin;$penv{PATH}"
|
||||
"PATH": "$env{SYSTEMDRIVE}/Qt/Tools/mingw1120_64/bin;$penv{PATH}"
|
||||
},
|
||||
"debug" : {
|
||||
"find" : true
|
||||
|
Reference in New Issue
Block a user