aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCristian Adam <cristian.adam@qt.io>2022-10-23 20:06:00 +0200
committerCristian Adam <cristian.adam@qt.io>2022-10-25 20:56:15 +0000
commitfb94873765f2db623d83f9fd660d7f6fa479ed5d (patch)
tree1db8ba9e111f9f730da7c9bfa7a041041d5164d1
parent83e77d71a899d387527f96e49746aec02fe83ae0 (diff)
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>
-rw-r--r--src/plugins/cmakeprojectmanager/presetsmacros.cpp39
-rw-r--r--src/plugins/cmakeprojectmanager/presetsparser.cpp18
-rw-r--r--src/plugins/cmakeprojectmanager/presetsparser.h5
-rw-r--r--tests/manual/cmakepresets/CMakePresets.json4
4 files changed, 36 insertions, 30 deletions
diff --git a/src/plugins/cmakeprojectmanager/presetsmacros.cpp b/src/plugins/cmakeprojectmanager/presetsmacros.cpp
index 0e156ab4a47..3ac96512388 100644
--- a/src/plugins/cmakeprojectmanager/presetsmacros.cpp
+++ b/src/plugins/cmakeprojectmanager/presetsmacros.cpp
@@ -99,22 +99,17 @@ static QString expandMacroEnv(const QString &macroPrefix,
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 &macroName) {
@@ -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 &macroName) {
- 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 &macroName) {
return presetEnv.value(macroName);
});
diff --git a/src/plugins/cmakeprojectmanager/presetsparser.cpp b/src/plugins/cmakeprojectmanager/presetsparser.cpp
index 3566bc1e081..6cddec91234 100644
--- a/src/plugins/cmakeprojectmanager/presetsparser.cpp
+++ b/src/plugins/cmakeprojectmanager/presetsparser.cpp
@@ -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>(
diff --git a/src/plugins/cmakeprojectmanager/presetsparser.h b/src/plugins/cmakeprojectmanager/presetsparser.h
index 7717f19c666..fdea1808719 100644
--- a/src/plugins/cmakeprojectmanager/presetsparser.h
+++ b/src/plugins/cmakeprojectmanager/presetsparser.h
@@ -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;
diff --git a/tests/manual/cmakepresets/CMakePresets.json b/tests/manual/cmakepresets/CMakePresets.json
index 50f3968a911..1b163830640 100644
--- a/tests/manual/cmakepresets/CMakePresets.json
+++ b/tests/manual/cmakepresets/CMakePresets.json
@@ -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