Fixed globbing when multiple extensions are present in the file name

main
Anthony Printup 7 months ago
parent 9288c8a87d
commit 33d4cc4156
No known key found for this signature in database
GPG Key ID: C8CB17EEA5183BD0

@ -20,7 +20,7 @@ description = "Globbing sources"
[target.mylib]
type = "static"
alias = "mylib::mylib"
sources = ["mylib/**.hpp", "mylib/**.cpp"]
sources = ["mylib/**.hpp", "mylib/**.cpp", "mylib/**.gen.cxx"]
include-directories = ["mylib/include"]
# Single-folder glob in example/src/

@ -55,31 +55,38 @@ static std::string format(const char *format, const tsl::ordered_map<std::string
}
static std::vector<std::string> expand_cmake_path(const fs::path &name, const fs::path &toml_dir, bool is_root_project) {
std::vector<std::string> temp;
auto extract_suffix = [](const fs::path &base, const fs::path &full) {
auto const extract_suffix = [](const fs::path &base, const fs::path &full) {
auto fullpath = full.string();
auto base_len = base.string().length();
auto delet = fullpath.substr(base_len + 1, fullpath.length() - base_len);
return delet;
return fullpath.substr(base_len + 1, fullpath.length() - base_len);
};
auto stem = name.filename().stem().string();
auto ext = name.extension();
auto const extract_path_parts = [](const fs::path &file_path) -> std::pair<std::string, std::string> {
const auto path_as_string = file_path.string();
auto const dot_position = path_as_string.find('.');
if (dot_position != std::string::npos) {
return {path_as_string.substr(0, dot_position), path_as_string.substr(dot_position)};
}
return {path_as_string, {}};
};
auto const path_parts = extract_path_parts(name.filename());
auto const &stem = path_parts.first;
auto const &extension = path_parts.second;
if (is_root_project && stem == "**" && name == name.filename()) {
throw std::runtime_error("Recursive globbing not allowed in project root: " + name.string());
}
std::vector<std::string> temp;
if (stem == "*") {
for (const auto &f : fs::directory_iterator(toml_dir / name.parent_path(), fs::directory_options::follow_directory_symlink)) {
if (!f.is_directory() && f.path().extension() == ext) {
if (!f.is_directory() && extract_path_parts(f.path().filename()).second == extension) {
temp.push_back(extract_suffix(toml_dir, f));
}
}
} else if (stem == "**") {
for (const auto &f : fs::recursive_directory_iterator(toml_dir / name.parent_path(), fs::directory_options::follow_directory_symlink)) {
if (!f.is_directory() && f.path().extension() == ext) {
if (!f.is_directory() && extract_path_parts(f.path().filename()).second == extension) {
temp.push_back(extract_suffix(toml_dir, f.path()));
}
}

@ -6,7 +6,7 @@ description = "Globbing sources"
[target.mylib]
type = "static"
alias = "mylib::mylib"
sources = ["mylib/**.hpp", "mylib/**.cpp"]
sources = ["mylib/**.hpp", "mylib/**.cpp", "mylib/**.gen.cxx"]
include-directories = ["mylib/include"]
# Single-folder glob in example/src/

@ -4,4 +4,5 @@
namespace mylib {
std::string message();
std::string message2();
}

@ -0,0 +1 @@
#error This file should not be included in the sources

@ -0,0 +1,5 @@
#include <mylib/mylib.hpp>
std::string mylib::message2() {
return "cmkr is awesome2!";
}
Loading…
Cancel
Save