forked from OSchip/llvm-project
Change library search methods to return Optional instead of ErrorOr.
These methods weren't really throwing errors. The only error used was that a file could not be found, which isn't really an error at all as we are searching paths and libraries for a file. All of the callers also ignored errors and just used the returned path if one was available. Changing to return Optional<StringRef> as that actually reflects what we are trying to do here: optionally find a given path. llvm-svn: 264979
This commit is contained in:
parent
dc59c794d0
commit
d0a643e7dc
|
|
@ -225,12 +225,12 @@ public:
|
||||||
/// The -lFoo option is documented to search for libFoo.dylib and libFoo.a in
|
/// The -lFoo option is documented to search for libFoo.dylib and libFoo.a in
|
||||||
/// that order, unless Foo ends in ".o", in which case only the exact file
|
/// that order, unless Foo ends in ".o", in which case only the exact file
|
||||||
/// matches (e.g. -lfoo.o would only find foo.o).
|
/// matches (e.g. -lfoo.o would only find foo.o).
|
||||||
ErrorOr<StringRef> searchDirForLibrary(StringRef path,
|
llvm::Optional<StringRef> searchDirForLibrary(StringRef path,
|
||||||
StringRef libName) const;
|
StringRef libName) const;
|
||||||
|
|
||||||
/// \brief Iterates through all search path entries looking for libName (as
|
/// \brief Iterates through all search path entries looking for libName (as
|
||||||
/// specified by -lFoo).
|
/// specified by -lFoo).
|
||||||
ErrorOr<StringRef> searchLibrary(StringRef libName) const;
|
llvm::Optional<StringRef> searchLibrary(StringRef libName) const;
|
||||||
|
|
||||||
/// Add a framework search path. Internally, this method may be prepended
|
/// Add a framework search path. Internally, this method may be prepended
|
||||||
/// the path with syslibroot.
|
/// the path with syslibroot.
|
||||||
|
|
@ -238,7 +238,7 @@ public:
|
||||||
|
|
||||||
/// \brief Iterates through all framework directories looking for
|
/// \brief Iterates through all framework directories looking for
|
||||||
/// Foo.framework/Foo (when fwName = "Foo").
|
/// Foo.framework/Foo (when fwName = "Foo").
|
||||||
ErrorOr<StringRef> findPathForFramework(StringRef fwName) const;
|
llvm::Optional<StringRef> findPathForFramework(StringRef fwName) const;
|
||||||
|
|
||||||
/// \brief The dylib's binary compatibility version, in the raw uint32 format.
|
/// \brief The dylib's binary compatibility version, in the raw uint32 format.
|
||||||
///
|
///
|
||||||
|
|
|
||||||
|
|
@ -1053,7 +1053,7 @@ bool parse(llvm::ArrayRef<const char *> args, MachOLinkingContext &ctx,
|
||||||
// Handle input files and sectcreate.
|
// Handle input files and sectcreate.
|
||||||
for (auto &arg : parsedArgs) {
|
for (auto &arg : parsedArgs) {
|
||||||
bool upward;
|
bool upward;
|
||||||
ErrorOr<StringRef> resolvedPath = StringRef();
|
llvm::Optional<StringRef> resolvedPath;
|
||||||
switch (arg->getOption().getID()) {
|
switch (arg->getOption().getID()) {
|
||||||
default:
|
default:
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -1076,9 +1076,10 @@ bool parse(llvm::ArrayRef<const char *> args, MachOLinkingContext &ctx,
|
||||||
return false;
|
return false;
|
||||||
} else if (ctx.testingFileUsage()) {
|
} else if (ctx.testingFileUsage()) {
|
||||||
diagnostics << "Found " << (upward ? "upward " : " ") << "library "
|
diagnostics << "Found " << (upward ? "upward " : " ") << "library "
|
||||||
<< canonicalizePath(resolvedPath.get()) << '\n';
|
<< canonicalizePath(resolvedPath.getValue()) << '\n';
|
||||||
}
|
}
|
||||||
addFile(resolvedPath.get(), ctx, globalWholeArchive, upward, diagnostics);
|
addFile(resolvedPath.getValue(), ctx, globalWholeArchive,
|
||||||
|
upward, diagnostics);
|
||||||
break;
|
break;
|
||||||
case OPT_framework:
|
case OPT_framework:
|
||||||
case OPT_upward_framework:
|
case OPT_upward_framework:
|
||||||
|
|
@ -1090,9 +1091,10 @@ bool parse(llvm::ArrayRef<const char *> args, MachOLinkingContext &ctx,
|
||||||
return false;
|
return false;
|
||||||
} else if (ctx.testingFileUsage()) {
|
} else if (ctx.testingFileUsage()) {
|
||||||
diagnostics << "Found " << (upward ? "upward " : " ") << "framework "
|
diagnostics << "Found " << (upward ? "upward " : " ") << "framework "
|
||||||
<< canonicalizePath(resolvedPath.get()) << '\n';
|
<< canonicalizePath(resolvedPath.getValue()) << '\n';
|
||||||
}
|
}
|
||||||
addFile(resolvedPath.get(), ctx, globalWholeArchive, upward, diagnostics);
|
addFile(resolvedPath.getValue(), ctx, globalWholeArchive,
|
||||||
|
upward, diagnostics);
|
||||||
break;
|
break;
|
||||||
case OPT_filelist:
|
case OPT_filelist:
|
||||||
if (auto ec = loadFileList(arg->getValue(),
|
if (auto ec = loadFileList(arg->getValue(),
|
||||||
|
|
|
||||||
|
|
@ -530,7 +530,7 @@ void MachOLinkingContext::addFrameworkSearchDir(StringRef fwPath,
|
||||||
_frameworkDirs.push_back(fwPath);
|
_frameworkDirs.push_back(fwPath);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<StringRef>
|
llvm::Optional<StringRef>
|
||||||
MachOLinkingContext::searchDirForLibrary(StringRef path,
|
MachOLinkingContext::searchDirForLibrary(StringRef path,
|
||||||
StringRef libName) const {
|
StringRef libName) const {
|
||||||
SmallString<256> fullPath;
|
SmallString<256> fullPath;
|
||||||
|
|
@ -540,7 +540,7 @@ MachOLinkingContext::searchDirForLibrary(StringRef path,
|
||||||
llvm::sys::path::append(fullPath, libName);
|
llvm::sys::path::append(fullPath, libName);
|
||||||
if (fileExists(fullPath))
|
if (fileExists(fullPath))
|
||||||
return fullPath.str().copy(_allocator);
|
return fullPath.str().copy(_allocator);
|
||||||
return make_error_code(llvm::errc::no_such_file_or_directory);
|
return llvm::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Search for dynamic library
|
// Search for dynamic library
|
||||||
|
|
@ -555,21 +555,23 @@ MachOLinkingContext::searchDirForLibrary(StringRef path,
|
||||||
if (fileExists(fullPath))
|
if (fileExists(fullPath))
|
||||||
return fullPath.str().copy(_allocator);
|
return fullPath.str().copy(_allocator);
|
||||||
|
|
||||||
return make_error_code(llvm::errc::no_such_file_or_directory);
|
return llvm::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<StringRef> MachOLinkingContext::searchLibrary(StringRef libName) const {
|
llvm::Optional<StringRef>
|
||||||
|
MachOLinkingContext::searchLibrary(StringRef libName) const {
|
||||||
SmallString<256> path;
|
SmallString<256> path;
|
||||||
for (StringRef dir : searchDirs()) {
|
for (StringRef dir : searchDirs()) {
|
||||||
ErrorOr<StringRef> ec = searchDirForLibrary(dir, libName);
|
llvm::Optional<StringRef> searchDir = searchDirForLibrary(dir, libName);
|
||||||
if (ec)
|
if (searchDir)
|
||||||
return ec;
|
return searchDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
return make_error_code(llvm::errc::no_such_file_or_directory);
|
return llvm::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorOr<StringRef> MachOLinkingContext::findPathForFramework(StringRef fwName) const{
|
llvm::Optional<StringRef>
|
||||||
|
MachOLinkingContext::findPathForFramework(StringRef fwName) const{
|
||||||
SmallString<256> fullPath;
|
SmallString<256> fullPath;
|
||||||
for (StringRef dir : frameworkDirs()) {
|
for (StringRef dir : frameworkDirs()) {
|
||||||
fullPath.assign(dir);
|
fullPath.assign(dir);
|
||||||
|
|
@ -578,7 +580,7 @@ ErrorOr<StringRef> MachOLinkingContext::findPathForFramework(StringRef fwName) c
|
||||||
return fullPath.str().copy(_allocator);
|
return fullPath.str().copy(_allocator);
|
||||||
}
|
}
|
||||||
|
|
||||||
return make_error_code(llvm::errc::no_such_file_or_directory);
|
return llvm::None;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool MachOLinkingContext::validateImpl(raw_ostream &diagnostics) {
|
bool MachOLinkingContext::validateImpl(raw_ostream &diagnostics) {
|
||||||
|
|
@ -706,9 +708,8 @@ MachODylibFile* MachOLinkingContext::findIndirectDylib(StringRef path) {
|
||||||
if (leafName.startswith("lib") && leafName.endswith(".dylib")) {
|
if (leafName.startswith("lib") && leafName.endswith(".dylib")) {
|
||||||
// FIXME: Need to enhance searchLibrary() to only look for .dylib
|
// FIXME: Need to enhance searchLibrary() to only look for .dylib
|
||||||
auto libPath = searchLibrary(leafName);
|
auto libPath = searchLibrary(leafName);
|
||||||
if (!libPath.getError()) {
|
if (libPath)
|
||||||
return loadIndirectDylib(libPath.get());
|
return loadIndirectDylib(libPath.getValue());
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Try full path with sysroot.
|
// Try full path with sysroot.
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue