3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-11-05 13:56:04 +00:00
This commit is contained in:
Emil J 2025-10-30 17:38:30 +01:00 committed by GitHub
commit adc1f8c4b5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 70 additions and 30 deletions

View file

@ -2,6 +2,7 @@
#include "kernel/log.h"
#include <iostream>
#include <string>
#include <filesystem>
#if !defined(WIN32)
#include <dirent.h>
@ -391,6 +392,30 @@ void append_globbed(std::vector<std::string>& paths, std::string pattern)
copy(globbed.begin(), globbed.end(), back_inserter(paths));
}
#ifdef _WIN32
const char* const OS_PATH_SEP = "/\\";
#else
const char* const OS_PATH_SEP = "/";
#endif
std::string name_from_file_path(std::string path) {
return std::filesystem::path(path).filename().string();
}
// Includes OS_PATH_SEP at the end if present
std::string parent_from_file_path(std::string path) {
auto parent = std::filesystem::path(path).parent_path();
if (parent.empty()) {
return "";
}
// Add trailing separator to match original behavior
std::string result = parent.string();
if (!result.empty() && result.back() != std::filesystem::path::preferred_separator) {
result += std::filesystem::path::preferred_separator;
}
return result;
}
void format_emit_unescaped(std::string &result, std::string_view fmt)
{
result.reserve(result.size() + fmt.size());

View file

@ -470,6 +470,8 @@ void remove_directory(std::string dirname);
bool create_directory(const std::string& dirname);
std::string escape_filename_spaces(const std::string& filename);
void append_globbed(std::vector<std::string>& paths, std::string pattern);
std::string name_from_file_path(std::string path);
std::string parent_from_file_path(std::string path);
YOSYS_NAMESPACE_END