Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vkconfig: Avoid duplicated paths #2121

Merged
merged 1 commit into from
Sep 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 6 additions & 4 deletions vkconfig_core/environment.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,8 +248,9 @@ bool Environment::Load() {
// assemble a list of paths that take precidence for layer discovery.
const QString VK_LAYER_PATH(qgetenv("VK_LAYER_PATH"));
if (!VK_LAYER_PATH.isEmpty()) {
this->user_defined_layers_paths[USER_DEFINED_LAYERS_PATHS_ENV_SET] =
ConvertString(QString(qgetenv("VK_LAYER_PATH")).split(SEPARATOR));
std::vector<std::string> paths = ConvertString(QString(qgetenv("VK_LAYER_PATH")).split(SEPARATOR));
paths = UniqueStrings(paths);
this->user_defined_layers_paths[USER_DEFINED_LAYERS_PATHS_ENV_SET] = paths;
} else {
this->user_defined_layers_paths[USER_DEFINED_LAYERS_PATHS_ENV_SET].clear();
}
Expand All @@ -258,8 +259,9 @@ bool Environment::Load() {
// assemble a list of paths that take precidence for layer discovery.
const QString VK_ADD_LAYER_PATH(qgetenv("VK_ADD_LAYER_PATH"));
if (!VK_ADD_LAYER_PATH.isEmpty()) {
this->user_defined_layers_paths[USER_DEFINED_LAYERS_PATHS_ENV_ADD] =
ConvertString(QString(qgetenv("VK_ADD_LAYER_PATH")).split(SEPARATOR));
std::vector<std::string> paths = ConvertString(QString(qgetenv("VK_ADD_LAYER_PATH")).split(SEPARATOR));
paths = UniqueStrings(paths);
this->user_defined_layers_paths[USER_DEFINED_LAYERS_PATHS_ENV_ADD] = paths;
} else {
this->user_defined_layers_paths[USER_DEFINED_LAYERS_PATHS_ENV_ADD].clear();
}
Expand Down
7 changes: 7 additions & 0 deletions vkconfig_core/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@

#include <cctype>
#include <regex>
#include <set>

std::string format(const char* message, ...) {
std::size_t const STRING_BUFFER(4096);
Expand Down Expand Up @@ -311,6 +312,12 @@ QStringList ConvertString(const std::vector<std::string>& strings) {
return string_list;
}

std::vector<std::string> UniqueStrings(const std::vector<std::string>& strings) {
std::set<std::string> uniques(strings.begin(), strings.end());
std::vector<std::string> results(uniques.begin(), uniques.end());
return results;
}

std::string ToLowerCase(const std::string& value) {
std::string result = value;

Expand Down
2 changes: 2 additions & 0 deletions vkconfig_core/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ std::vector<std::string> ConvertString(const QStringList& string_list);

QStringList ConvertString(const std::vector<std::string>& strings);

std::vector<std::string> UniqueStrings(const std::vector<std::string>& strings);

std::string ToLowerCase(const std::string& value);

std::string ToUpperCase(const std::string& value);
Expand Down