3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-10-11 02:08:08 +00:00
This commit is contained in:
Emil J 2025-10-08 13:37:04 +13:00 committed by GitHub
commit cf766acb23
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 28 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>
@ -384,6 +385,24 @@ std::string escape_filename_spaces(const std::string& filename)
return out;
}
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

@ -469,6 +469,8 @@ bool is_absolute_path(std::string filename);
void remove_directory(std::string dirname);
bool create_directory(const std::string& dirname);
std::string escape_filename_spaces(const std::string& filename);
std::string name_from_file_path(std::string path);
std::string parent_from_file_path(std::string path);
YOSYS_NAMESPACE_END