chore: do not add duplicate paths in LinkerPaths

This commit is contained in:
Jan 2024-11-17 22:11:18 +01:00
parent a240824706
commit 63046f5681
No known key found for this signature in database
GPG Key ID: 44B581F78FF5C57C

View File

@ -12,6 +12,7 @@
#include <iostream> #include <iostream>
#include <sstream> #include <sstream>
#include <type_traits> #include <type_traits>
#include <unordered_set>
namespace fs = std::filesystem; namespace fs = std::filesystem;
@ -163,6 +164,7 @@ namespace
[[nodiscard]] std::unique_ptr<ISearchPath> BuildIndependentSearchPaths() const override [[nodiscard]] std::unique_ptr<ISearchPath> BuildIndependentSearchPaths() const override
{ {
SearchPaths searchPaths; SearchPaths searchPaths;
std::unordered_set<std::string> addedSearchPaths;
auto hasSearchPath = false; auto hasSearchPath = false;
for (const auto& curTemplate : m_templates) for (const auto& curTemplate : m_templates)
@ -170,7 +172,7 @@ namespace
if (curTemplate.CanRender(INDEPENDENT_MASK)) if (curTemplate.CanRender(INDEPENDENT_MASK))
{ {
auto renderedTemplate = curTemplate.Render(m_bin_dir, m_base_dir, std::string(), std::string()); auto renderedTemplate = curTemplate.Render(m_bin_dir, m_base_dir, std::string(), std::string());
if (AddSearchPath(searchPaths, renderedTemplate)) if (AddSearchPath(addedSearchPaths, searchPaths, renderedTemplate))
hasSearchPath = true; hasSearchPath = true;
} }
} }
@ -184,6 +186,7 @@ namespace
[[nodiscard]] std::unique_ptr<ISearchPath> BuildSearchPathsSpecificToProject(const std::string& projectName) const override [[nodiscard]] std::unique_ptr<ISearchPath> BuildSearchPathsSpecificToProject(const std::string& projectName) const override
{ {
SearchPaths searchPaths; SearchPaths searchPaths;
std::unordered_set<std::string> addedSearchPaths;
auto hasSearchPath = false; auto hasSearchPath = false;
for (const auto& curTemplate : m_templates) for (const auto& curTemplate : m_templates)
@ -191,7 +194,7 @@ namespace
if (!curTemplate.CanRender(INDEPENDENT_MASK) && curTemplate.CanRender(PROJECT_MASK)) if (!curTemplate.CanRender(INDEPENDENT_MASK) && curTemplate.CanRender(PROJECT_MASK))
{ {
auto renderedTemplate = curTemplate.Render(m_bin_dir, m_base_dir, projectName, std::string()); auto renderedTemplate = curTemplate.Render(m_bin_dir, m_base_dir, projectName, std::string());
if (AddSearchPath(searchPaths, renderedTemplate)) if (AddSearchPath(addedSearchPaths, searchPaths, renderedTemplate))
hasSearchPath = true; hasSearchPath = true;
} }
} }
@ -205,6 +208,7 @@ namespace
[[nodiscard]] std::unique_ptr<ISearchPath> BuildSearchPathsSpecificToProjectAndGame(const std::string& projectName, GameId game) const override [[nodiscard]] std::unique_ptr<ISearchPath> BuildSearchPathsSpecificToProjectAndGame(const std::string& projectName, GameId game) const override
{ {
SearchPaths searchPaths; SearchPaths searchPaths;
std::unordered_set<std::string> addedSearchPaths;
auto hasSearchPath = false; auto hasSearchPath = false;
for (const auto& curTemplate : m_templates) for (const auto& curTemplate : m_templates)
@ -212,7 +216,7 @@ namespace
if (!curTemplate.CanRender(PROJECT_MASK) && curTemplate.CanRender(GAME_MASK)) if (!curTemplate.CanRender(PROJECT_MASK) && curTemplate.CanRender(GAME_MASK))
{ {
auto renderedTemplate = curTemplate.Render(m_bin_dir, m_base_dir, projectName, GameId_Names[static_cast<unsigned>(game)]); auto renderedTemplate = curTemplate.Render(m_bin_dir, m_base_dir, projectName, GameId_Names[static_cast<unsigned>(game)]);
if (AddSearchPath(searchPaths, renderedTemplate)) if (AddSearchPath(addedSearchPaths, searchPaths, renderedTemplate))
hasSearchPath = true; hasSearchPath = true;
} }
} }
@ -224,8 +228,13 @@ namespace
} }
private: private:
bool AddSearchPath(SearchPaths& searchPaths, const std::string& path) const bool AddSearchPath(std::unordered_set<std::string>& existingSearchPaths, SearchPaths& searchPaths, const std::string& path) const
{ {
const auto existingSearchPath = existingSearchPaths.find(path);
if (existingSearchPath != existingSearchPaths.end())
return false;
existingSearchPaths.emplace(path);
if (!fs::is_directory(path)) if (!fs::is_directory(path))
{ {
std::cout << std::format("Adding {} search path (Not found): {}\n", m_type_name, path); std::cout << std::format("Adding {} search path (Not found): {}\n", m_type_name, path);