|
14 | 14 | #include <tl/expected.hpp> |
15 | 15 |
|
16 | 16 | #include <algorithm> |
| 17 | +#include <cctype> |
17 | 18 | #include <deque> |
18 | 19 | #include <filesystem> |
19 | 20 | #include <fstream> |
@@ -136,19 +137,46 @@ namespace cps::search { |
136 | 137 | return std::vector<fs::path>{name}; |
137 | 138 | } |
138 | 139 |
|
| 140 | + // If the given name is not all lower, we need to search that as well. |
| 141 | + std::vector<std::string> names{std::string{name}}; |
| 142 | + std::string lc{name}; |
| 143 | + std::transform(lc.begin(), lc.end(), lc.begin(), [](const unsigned char ch) { return std::tolower(ch); }); |
| 144 | + if (name != lc) { |
| 145 | + names.push_back(lc); |
| 146 | + } |
| 147 | + |
139 | 148 | // TODO: Need something like pkgconf's --personality option |
140 | 149 | // TODO: we likely either need to return all possible files, or load |
141 | 150 | // a file |
142 | 151 | // TODO: what to do about finding multiple versions of the same |
143 | 152 | // dependency? |
| 153 | + |
| 154 | + // Each prefix must be searched for (assuming Name is the term): |
| 155 | + // |
| 156 | + // - Name/*.cps |
| 157 | + // - name/*.cps |
| 158 | + // - Name.cps |
| 159 | + // - name.cps |
| 160 | + // |
| 161 | + // TODO: should we allow symlinks? |
144 | 162 | auto && paths = search_paths(env); |
145 | 163 | std::vector<fs::path> found{}; |
146 | | - for (auto && path : paths) { |
147 | | - if (fs::is_directory(path)) { |
148 | | - // TODO: <name-like> |
149 | | - const fs::path file = path / fmt::format("{}.cps", name); |
150 | | - if (fs::is_regular_file(file)) { |
151 | | - found.push_back(file); |
| 164 | + for (auto && cname : names) { |
| 165 | + for (auto && path : paths) { |
| 166 | + if (fs::is_directory(path)) { |
| 167 | + const fs::path namelike = path / cname; |
| 168 | + if (fs::is_directory(namelike)) { |
| 169 | + for (auto && trial : fs::directory_iterator(namelike)) { |
| 170 | + auto && tpath = trial.path(); |
| 171 | + if (fs::is_regular_file(tpath) && tpath.extension() == ".cps") { |
| 172 | + found.push_back(tpath); |
| 173 | + } |
| 174 | + } |
| 175 | + } |
| 176 | + const fs::path file = path / fmt::format("{}.cps", cname); |
| 177 | + if (fs::is_regular_file(file)) { |
| 178 | + found.push_back(file); |
| 179 | + } |
152 | 180 | } |
153 | 181 | } |
154 | 182 | } |
@@ -402,7 +430,7 @@ namespace cps::search { |
402 | 430 |
|
403 | 431 | } // namespace |
404 | 432 |
|
405 | | - Result::Result(){}; |
| 433 | + Result::Result() {}; |
406 | 434 |
|
407 | 435 | tl::expected<Result, std::string> find_package(std::string_view name, Env env) { |
408 | 436 | return find_package(name, {}, true, env, std::nullopt); |
|
0 commit comments