forked from OSchip/llvm-project
Make buildSysrootedPath file-scoped.
This patch also changes its return type to simplify callers. llvm-svn: 287455
This commit is contained in:
parent
844c1c908c
commit
ec75220fe9
|
@ -74,7 +74,6 @@ std::string createResponseFile(const llvm::opt::InputArgList &Args);
|
|||
|
||||
std::string findFromSearchPaths(StringRef Path);
|
||||
std::string searchLibrary(StringRef Path);
|
||||
std::string buildSysrootedPath(llvm::StringRef Dir, llvm::StringRef File);
|
||||
|
||||
} // namespace elf
|
||||
} // namespace lld
|
||||
|
|
|
@ -18,6 +18,7 @@
|
|||
#include "Memory.h"
|
||||
#include "lld/Config/Version.h"
|
||||
#include "lld/Core/Reproduce.h"
|
||||
#include "llvm/ADT/Optional.h"
|
||||
#include "llvm/ADT/STLExtras.h"
|
||||
#include "llvm/ADT/Triple.h"
|
||||
#include "llvm/Option/Option.h"
|
||||
|
@ -123,41 +124,38 @@ std::string elf::createResponseFile(const opt::InputArgList &Args) {
|
|||
return Data.str();
|
||||
}
|
||||
|
||||
std::string elf::findFromSearchPaths(StringRef Path) {
|
||||
for (StringRef Dir : Config->SearchPaths) {
|
||||
std::string FullPath = buildSysrootedPath(Dir, Path);
|
||||
if (fs::exists(FullPath))
|
||||
return FullPath;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// Searches a given library from input search paths, which are filled
|
||||
// from -L command line switches. Returns a path to an existent library file.
|
||||
std::string elf::searchLibrary(StringRef Path) {
|
||||
if (Path.startswith(":"))
|
||||
return findFromSearchPaths(Path.substr(1));
|
||||
for (StringRef Dir : Config->SearchPaths) {
|
||||
if (!Config->Static) {
|
||||
std::string S = buildSysrootedPath(Dir, ("lib" + Path + ".so").str());
|
||||
if (fs::exists(S))
|
||||
return S;
|
||||
}
|
||||
std::string S = buildSysrootedPath(Dir, ("lib" + Path + ".a").str());
|
||||
if (fs::exists(S))
|
||||
return S;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
// Makes a path by concatenating Dir and File.
|
||||
// If Dir starts with '=' the result will be preceded by Sysroot,
|
||||
// which can be set with --sysroot command line switch.
|
||||
std::string elf::buildSysrootedPath(StringRef Dir, StringRef File) {
|
||||
SmallString<128> Path;
|
||||
if (Dir.startswith("="))
|
||||
path::append(Path, Config->Sysroot, Dir.substr(1), File);
|
||||
// Find a file by concatenating given paths. If a resulting path
|
||||
// starts with "=", the character is replaced with a --sysroot value.
|
||||
static Optional<std::string> findFile(StringRef Path1, const Twine &Path2) {
|
||||
SmallString<128> S;
|
||||
if (Path1.startswith("="))
|
||||
path::append(S, Config->Sysroot, Path1.substr(1), Path2);
|
||||
else
|
||||
path::append(Path, Dir, File);
|
||||
return Path.str();
|
||||
path::append(S, Path1, Path2);
|
||||
|
||||
if (fs::exists(S))
|
||||
return S.str().str();
|
||||
return None;
|
||||
}
|
||||
|
||||
std::string elf::findFromSearchPaths(StringRef Path) {
|
||||
for (StringRef Dir : Config->SearchPaths)
|
||||
if (Optional<std::string> S = findFile(Dir, Path))
|
||||
return *S;
|
||||
return "";
|
||||
}
|
||||
|
||||
// This is for -lfoo. We'll look for libfoo.so or libfoo.a from
|
||||
// search paths.
|
||||
std::string elf::searchLibrary(StringRef Name) {
|
||||
if (Name.startswith(":"))
|
||||
return findFromSearchPaths(Name.substr(1));
|
||||
for (StringRef Dir : Config->SearchPaths) {
|
||||
if (!Config->Static)
|
||||
if (Optional<std::string> S = findFile(Dir, "lib" + Name + ".so"))
|
||||
return *S;
|
||||
if (Optional<std::string> S = findFile(Dir, "lib" + Name + ".a"))
|
||||
return *S;
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue