/// 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
/// matches (e.g. -lfoo.o would only find foo.o).
- ErrorOr<StringRef> searchDirForLibrary(StringRef path,
- StringRef libName) const;
+ llvm::Optional<StringRef> searchDirForLibrary(StringRef path,
+ StringRef libName) const;
/// \brief Iterates through all search path entries looking for libName (as
/// 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
/// the path with syslibroot.
/// \brief Iterates through all framework directories looking for
/// 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.
///
// Handle input files and sectcreate.
for (auto &arg : parsedArgs) {
bool upward;
- ErrorOr<StringRef> resolvedPath = StringRef();
+ llvm::Optional<StringRef> resolvedPath;
switch (arg->getOption().getID()) {
default:
continue;
return false;
} else if (ctx.testingFileUsage()) {
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;
case OPT_framework:
case OPT_upward_framework:
return false;
} else if (ctx.testingFileUsage()) {
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;
case OPT_filelist:
if (auto ec = loadFileList(arg->getValue(),
_frameworkDirs.push_back(fwPath);
}
-ErrorOr<StringRef>
+llvm::Optional<StringRef>
MachOLinkingContext::searchDirForLibrary(StringRef path,
StringRef libName) const {
SmallString<256> fullPath;
llvm::sys::path::append(fullPath, libName);
if (fileExists(fullPath))
return fullPath.str().copy(_allocator);
- return make_error_code(llvm::errc::no_such_file_or_directory);
+ return llvm::None;
}
// Search for dynamic library
if (fileExists(fullPath))
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;
for (StringRef dir : searchDirs()) {
- ErrorOr<StringRef> ec = searchDirForLibrary(dir, libName);
- if (ec)
- return ec;
+ llvm::Optional<StringRef> searchDir = searchDirForLibrary(dir, libName);
+ if (searchDir)
+ 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;
for (StringRef dir : frameworkDirs()) {
fullPath.assign(dir);
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) {
if (leafName.startswith("lib") && leafName.endswith(".dylib")) {
// FIXME: Need to enhance searchLibrary() to only look for .dylib
auto libPath = searchLibrary(leafName);
- if (!libPath.getError()) {
- return loadIndirectDylib(libPath.get());
- }
+ if (libPath)
+ return loadIndirectDylib(libPath.getValue());
}
// Try full path with sysroot.