1//===- InterfaceFile.cpp --------------------------------------------------===// 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 7//===----------------------------------------------------------------------===// 9// Implements the Interface File. 11//===----------------------------------------------------------------------===// 28if (InstallName.
empty())
30auto Client =
addEntry(AllowableClients, InstallName);
36if (InstallName.
empty())
46 [](
const std::pair<Target, std::string> &
LHS,
49if ((Iter != ParentUmbrellas.end()) && !(Target_ < Iter->first)) {
50 Iter->second = std::string(Parent);
54 ParentUmbrellas.emplace(Iter, Target_, std::string(Parent));
60usingRPathEntryT =
const std::pair<Target, std::string>;
61 RPathEntryT Entry(InputTarget, RPath);
64 [](RPathEntryT &
LHS, RPathEntryT &
RHS) {
returnLHS <
RHS; });
66if ((Iter != RPaths.end()) && (*Iter == Entry))
69 RPaths.emplace(Iter, Entry);
79return Archs.
has(Target_.Arch);
86 [](
const std::shared_ptr<InterfaceFile> &
LHS,
87const std::shared_ptr<InterfaceFile> &
RHS) {
88returnLHS->InstallName <
RHS->InstallName;
90assert((Pos == Documents.end() ||
91 (*Pos)->InstallName != Document->InstallName) &&
92"Unexpected duplicate document added");
93 Document->Parent =
this;
94 Documents.insert(Pos, Document);
99auto AddFwk = [&](std::shared_ptr<InterfaceFile> &&Reexport) {
101 Documents, Reexport->getInstallName(),
102 [](std::shared_ptr<InterfaceFile> &Lhs,
constStringRef Rhs) {
103 return Lhs->getInstallName() < Rhs;
106if (Overwrite && It != Documents.end() &&
107 Reexport->getInstallName() == (*It)->getInstallName()) {
108 std::replace(Documents.begin(), Documents.end(), *It,
109 std::move(Reexport));
113if ((It != Documents.end()) &&
114 !(Reexport->getInstallName() < (*It)->getInstallName()))
117 Documents.emplace(It, std::move(Reexport));
119for (
auto Doc : Library->documents())
120 AddFwk(std::move(Doc));
122 Library->Documents.clear();
123 AddFwk(std::move(Library));
128// Verify files can be merged. 130return make_error<StringError>(
"install names do not match",
135return make_error<StringError>(
"current versions do not match",
140return make_error<StringError>(
"compatibility versions do not match",
146return make_error<StringError>(
"swift ABI versions do not match",
151return make_error<StringError>(
"two level namespace flags do not match",
156return make_error<StringError>(
157"application extension safe flags do not match",
162 IF->setFileType(std::max(
getFileType(), O->getFileType()));
169 IF->setSwiftABIVersion(O->getSwiftABIVersion());
178if (!It.second.empty())
179 IF->addParentUmbrella(It.first, It.second);
181for (
constauto &It : O->umbrellas()) {
182if (!It.second.empty())
183 IF->addParentUmbrella(It.first, It.second);
186 IF->addTargets(O->targets());
190 IF->addAllowableClient(
Lib.getInstallName(),
Target);
192for (
constauto &
Lib : O->allowableClients())
194 IF->addAllowableClient(
Lib.getInstallName(),
Target);
198 IF->addReexportedLibrary(
Lib.getInstallName(),
Target);
200for (
constauto &
Lib : O->reexportedLibraries())
202 IF->addReexportedLibrary(
Lib.getInstallName(),
Target);
205 IF->addRPath(Path,
Target);
206for (
constauto &[
Target, Path] : O->rpaths())
207 IF->addRPath(Path,
Target);
214for (
constauto *
Sym : O->symbols()) {
225return make_error<StringError>(
"cannot remove last architecture slice '" +
231for (
auto &Doc : Documents) {
232if (Doc->getArchitectures().has(Arch)) {
242// FIXME: Figure out how to keep these attributes in sync when new ones are 256if (It.first.Arch != Arch)
257 IF->addParentUmbrella(It.first, It.second);
262 IF->addAllowableClient(
Lib.getInstallName(),
Target);
268 IF->addReexportedLibrary(
Lib.getInstallName(),
Target);
281for (
auto &Doc : Documents) {
282// Skip the inlined document if the to be removed architecture is the 284if (Doc->getArchitectures() == Arch)
287// If the document doesn't contain the arch, then no work is to be done 288// and it can be copied over. 289if (!Doc->getArchitectures().has(Arch)) {
291 IF->addDocument(std::move(NewDoc));
295auto Result = Doc->remove(Arch);
299 IF->addDocument(std::move(Result.get()));
308return make_error<StringError>(
"file doesn't have architecture '" +
325if (It.first.Arch == Arch)
326 IF->addParentUmbrella(It.first, It.second);
328for (
constauto &It :
rpaths())
329if (It.first.Arch == Arch)
330 IF->addRPath(It.second, It.first);
335 IF->addAllowableClient(
Lib.getInstallName(),
Target);
340 IF->addReexportedLibrary(
Lib.getInstallName(),
Target);
348for (
auto &Doc : Documents) {
349// Skip documents that don't have the requested architecture. 350if (!Doc->getArchitectures().has(Arch))
353auto Result = Doc->extract(Arch);
357 IF->addDocument(std::move(Result.get()));
396if (Targets != O.Targets)
398if (InstallName != O.InstallName)
400if ((CurrentVersion != O.CurrentVersion) ||
401 (CompatibilityVersion != O.CompatibilityVersion))
403if (SwiftABIVersion != O.SwiftABIVersion)
405if (IsTwoLevelNamespace != O.IsTwoLevelNamespace)
407if (IsAppExtensionSafe != O.IsAppExtensionSafe)
409if (IsOSLibNotForSharedCache != O.IsOSLibNotForSharedCache)
411if (HasSimSupport != O.HasSimSupport)
413if (ParentUmbrellas != O.ParentUmbrellas)
415if (AllowableClients != O.AllowableClients)
417if (ReexportedLibraries != O.ReexportedLibraries)
419if (*SymbolsSet != *O.SymbolsSet)
421// Don't compare run search paths for older filetypes that cannot express 424if (RPaths != O.RPaths)
430if (!std::equal(Documents.begin(), Documents.end(), O.Documents.begin(),
432 [](
const std::shared_ptr<InterfaceFile>
LHS,
433const std::shared_ptr<InterfaceFile>
RHS) {
static bool isYAMLTextStub(const FileType &Kind)
Implements the TAPI Record Collection Type.
assert(ImpDefSCC.getReg()==AMDGPU::SCC &&ImpDefSCC.isDef())
Define TAPI specific error codes.
Tagged union holding either a T or a Error.
static ArchitectureSet All()
ArchitectureSet clear(Architecture Arch)
bool has(Architecture Arch) const
void addTarget(const Target &Target)
Defines the interface file.
void addDocument(std::shared_ptr< InterfaceFile > &&Document)
Add a library for inlining to top level library.
StringRef getPath() const
Get the path from which this file was generated (if applicable).
void addReexportedLibrary(StringRef InstallName, const Target &Target)
Add a re-exported library.
void setPath(StringRef Path_)
Set the path from which this file was generated (if applicable).
void setFromBinaryAttrs(const RecordsSlice::BinaryAttrs &BA, const Target &Targ)
Set InterfaceFile properties from pre-gathered binary attributes, if they are not set already.
void addParentUmbrella(const Target &Target_, StringRef Parent)
Set the parent umbrella frameworks.
const_target_range targets() const
void setOSLibNotForSharedCache(bool V=true)
Specify if the library is an OS library but not shared cache eligible.
bool isOSLibNotForSharedCache() const
Check if the library is an OS library that is not shared cache eligible.
llvm::Expected< std::unique_ptr< InterfaceFile > > remove(Architecture Arch) const
Remove architecture slice from Interface.
bool isTwoLevelNamespace() const
Check if the library uses two-level namespace.
bool operator==(const InterfaceFile &O) const
The equality is determined by attributes that impact linking compatibilities.
PackedVersion getCompatibilityVersion() const
Get the compatibility version of the library.
void addTarget(const Target &Target)
Set and add target.
bool isApplicationExtensionSafe() const
Check if the library is application extension safe.
const std::vector< std::pair< Target, std::string > > & rpaths() const
Get the list of runpath search paths.
const std::vector< InterfaceFileRef > & allowableClients() const
Get the list of allowable clients.
void setInstallName(StringRef InstallName_)
Set the install name of the library.
const std::vector< std::pair< Target, std::string > > & umbrellas() const
Get the list of Parent Umbrella frameworks.
const std::vector< InterfaceFileRef > & reexportedLibraries() const
Get the list of re-exported libraries.
const_symbol_range symbols() const
void setFileType(FileType Kind)
Set the file type.
uint8_t getSwiftABIVersion() const
Get the Swift ABI version of the library.
PackedVersion getCurrentVersion() const
Get the current version of the library.
void addRPath(StringRef RPath, const Target &InputTarget)
Set the runpath search paths.
void setCompatibilityVersion(PackedVersion Version)
Set the compatibility version of the library.
ArchitectureSet getArchitectures() const
Get the architectures.
StringRef getInstallName() const
Get the install name of the library.
llvm::Expected< std::unique_ptr< InterfaceFile > > merge(const InterfaceFile *O) const
Merge Interfaces for the same library.
FileType getFileType() const
Get the file type.
void setApplicationExtensionSafe(bool V=true)
Specify if the library is application extension safe (or not).
void addAllowableClient(StringRef InstallName, const Target &Target)
Add an allowable client.
void inlineLibrary(std::shared_ptr< InterfaceFile > Library, bool Overwrite=false)
Inline reexported library into Interface.
void setSwiftABIVersion(uint8_t Version)
Set the Swift ABI version of the library.
void setCurrentVersion(PackedVersion Version)
Set the current version of the library.
llvm::Expected< std::unique_ptr< InterfaceFile > > extract(Architecture Arch) const
Extract architecture slice from Interface.
void setTwoLevelNamespace(bool V=true)
Specify if the library uses two-level namespace (or flat namespace).
SymbolFlags getFlags() const
bool hasArchitecture(Architecture Arch) const
const_target_range targets() const
ArchitectureSet getArchitectures() const
StringRef getName() const
EncodeKind getKind() const
StringRef - Represent a constant reference to a string, i.e.
constexpr bool empty() const
empty - Check if the string is empty.
A range adaptor for a pair of iterators.
FileType
Defines the file type TextAPI files can represent.
@ TBD_V1
Text-based stub file (.tbd) version 1.0.
@ TBD_V5
Text-based stub file (.tbd) version 5.0.
StringRef getArchitectureName(Architecture Arch)
Convert an architecture slice to a string.
C::iterator addEntry(C &Container, StringRef InstallName)
Architecture
Defines the architecture slices that are supported by Text-based Stub files.
PlatformVersionSet mapToPlatformVersionSet(ArrayRef< Target > Targets)
This is an optimization pass for GlobalISel generic memory operations.
std::error_code inconvertibleErrorCode()
The value returned by this function can be returned from convertToErrorCode for Error values where no...
iterator_range< filter_iterator< detail::IterOfRange< RangeT >, PredicateT > > make_filter_range(RangeT &&Range, PredicateT Pred)
Convenience function that takes a range of elements and a predicate, and return a new filter_iterator...
auto lower_bound(R &&Range, T &&Value)
Provide wrappers to std::lower_bound which take ranges instead of having to pass begin/end explicitly...
std::vector< StringRef > RexportedLibraries
std::vector< StringRef > AllowableClients
llvm::MachO::PackedVersion CompatVersion
llvm::MachO::PackedVersion CurrentVersion
bool OSLibNotForSharedCache