mirror of
https://github.com/rui314/mold.git
synced 2024-09-11 21:17:28 +03:00
With toolchains using a relative sysroot, like crosstool-ng, gcc/clang will call the linker with something like "--sysroot=/path/bin/../machine/sysroot". The is_in_sysroot detection wasn't working in this case. Since to_abs_path() uses lexically_normal() for relative paths, it seems consistent to do the same for absolute paths instead of modifying is_in_sysroot().
28 lines
746 B
C++
28 lines
746 B
C++
#include "mold.h"
|
|
|
|
#include <filesystem>
|
|
#include <sys/stat.h>
|
|
|
|
namespace mold {
|
|
|
|
std::string get_realpath(std::string_view path) {
|
|
std::error_code ec;
|
|
std::string ret = std::filesystem::canonical(path, ec).string();
|
|
return ec ? std::string(path) : ret;
|
|
}
|
|
|
|
// Removes redundant '/..' or '/.' from a given path.
|
|
// The transformation is done purely by lexical processing.
|
|
// This function does not access file system.
|
|
std::string path_clean(std::string_view path) {
|
|
return filepath(path).lexically_normal().string();
|
|
}
|
|
|
|
std::filesystem::path to_abs_path(std::filesystem::path path) {
|
|
if (path.is_absolute())
|
|
return path.lexically_normal();
|
|
return (std::filesystem::current_path() / path).lexically_normal();
|
|
}
|
|
|
|
} // namespace mold
|