mirror of
https://github.com/rui314/mold.git
synced 2024-09-21 09:57:18 +03:00
Display simplified pathnames
This commit is contained in:
parent
8f56251864
commit
f2db8be4b9
49
filepath.cc
49
filepath.cc
@ -22,3 +22,52 @@ std::string path_basename(std::string_view path) {
|
||||
return std::string(path);
|
||||
return std::string(path.substr(pos + 1));
|
||||
}
|
||||
|
||||
std::string path_clean(std::string_view path) {
|
||||
std::vector<std::string_view> components;
|
||||
bool is_rooted = path.starts_with('/');
|
||||
|
||||
while (!path.empty()) {
|
||||
size_t pos = path.find('/');
|
||||
std::string_view elem;
|
||||
|
||||
if (pos == path.npos) {
|
||||
elem = path;
|
||||
path = "";
|
||||
} else {
|
||||
elem = path.substr(0, pos);
|
||||
path = path.substr(pos + 1);
|
||||
}
|
||||
|
||||
if (elem.empty() || elem == ".")
|
||||
continue;
|
||||
|
||||
if (elem == "..") {
|
||||
if (components.empty()) {
|
||||
if (is_rooted)
|
||||
continue;
|
||||
components.push_back("..");
|
||||
continue;
|
||||
}
|
||||
|
||||
if (components.back() == "..")
|
||||
components.push_back("..");
|
||||
else
|
||||
components.pop_back();
|
||||
continue;
|
||||
}
|
||||
|
||||
components.push_back(elem);
|
||||
}
|
||||
|
||||
std::string ret;
|
||||
if (is_rooted)
|
||||
ret = "/";
|
||||
|
||||
for (i64 i = 0, end = components.size(); i < end; i++) {
|
||||
ret += components[i];
|
||||
if (i != end - 1)
|
||||
ret += "/";
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
1
mold.h
1
mold.h
@ -1092,6 +1092,7 @@ protected:
|
||||
|
||||
std::string path_dirname(std::string_view path);
|
||||
std::string path_basename(std::string_view path);
|
||||
std::string path_clean(std::string_view path);
|
||||
|
||||
//
|
||||
// perf.cc
|
||||
|
@ -994,15 +994,15 @@ ObjectFile::ObjectFile() {
|
||||
|
||||
std::ostream &operator<<(std::ostream &out, const InputFile &file) {
|
||||
if (file.is_dso) {
|
||||
out << file.name;
|
||||
out << path_clean(file.name);
|
||||
return out;
|
||||
}
|
||||
|
||||
ObjectFile *obj = (ObjectFile *)&file;
|
||||
if (obj->archive_name == "")
|
||||
out << obj->name;
|
||||
out << path_clean(obj->name);
|
||||
else
|
||||
out << obj->archive_name << "(" << obj->name + ")";
|
||||
out << path_clean(obj->archive_name) << "(" << obj->name + ")";
|
||||
return out;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user