mirror of
https://github.com/YosysHQ/yosys
synced 2025-11-08 15:25:08 +00:00
Merge pull request #4596 from YosysHQ/emil/path-sep-refactor
Refactor getting dirs and filenames from paths to files
This commit is contained in:
commit
52c108cd6a
10 changed files with 64 additions and 30 deletions
19
kernel/io.cc
19
kernel/io.cc
|
|
@ -2,6 +2,7 @@
|
|||
#include "kernel/log.h"
|
||||
#include <iostream>
|
||||
#include <string>
|
||||
#include <filesystem>
|
||||
|
||||
#if !defined(WIN32)
|
||||
#include <dirent.h>
|
||||
|
|
@ -391,6 +392,24 @@ void append_globbed(std::vector<std::string>& paths, std::string pattern)
|
|||
copy(globbed.begin(), globbed.end(), back_inserter(paths));
|
||||
}
|
||||
|
||||
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());
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue