[Dexter][NFC] Add Missing Commands to Commands.md Contents
[llvm-project.git] / lld / MachO / DriverUtils.cpp
blobfa0b62e11c4935fa3413af9821d2e05dd817255a
1 //===- DriverUtils.cpp ----------------------------------------------------===//
2 //
3 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4 // See https://llvm.org/LICENSE.txt for license information.
5 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6 //
7 //===----------------------------------------------------------------------===//
9 #include "DriverUtils.h"
10 #include "InputFiles.h"
12 #include "lld/Common/ErrorHandler.h"
13 #include "lld/Common/Memory.h"
14 #include "llvm/Support/Path.h"
15 #include "llvm/TextAPI/MachO/TextAPIReader.h"
17 using namespace llvm;
18 using namespace llvm::MachO;
19 using namespace llvm::sys;
20 using namespace lld;
21 using namespace lld::macho;
23 Optional<std::string> macho::resolveDylibPath(StringRef path) {
24 // TODO: if a tbd and dylib are both present, we should check to make sure
25 // they are consistent.
26 if (fs::exists(path))
27 return std::string(path);
29 SmallString<261> location = path;
30 path::replace_extension(location, ".tbd");
31 if (fs::exists(location))
32 return std::string(location);
34 return {};
37 Optional<DylibFile *> macho::makeDylibFromTAPI(MemoryBufferRef mbref,
38 DylibFile *umbrella) {
39 Expected<std::unique_ptr<InterfaceFile>> result = TextAPIReader::get(mbref);
40 if (!result) {
41 error("could not load TAPI file at " + mbref.getBufferIdentifier() + ": " +
42 toString(result.takeError()));
43 return {};
45 return make<DylibFile>(**result, umbrella);