LLVM 19.0.0git
Utils.h
Go to the documentation of this file.
1//===- llvm/TextAPI/Utils.h - TAPI Utils -----------------------*- C++ -*-===//
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//===----------------------------------------------------------------------===//
8//
9// Helper functionality used for Darwin specific operations.
10//
11//===----------------------------------------------------------------------===//
12
13#ifndef LLVM_TEXTAPI_UTILS_H
14#define LLVM_TEXTAPI_UTILS_H
15
16#include "llvm/ADT/Twine.h"
17#include "llvm/Support/Error.h"
20#include "llvm/Support/Path.h"
21#include "llvm/Support/Regex.h"
22#include "llvm/TextAPI/Symbol.h"
23#include <map>
24
25#if !defined(PATH_MAX)
26#define PATH_MAX 1024
27#endif // !defined(PATH_MAX)
28
29#define MACCATALYST_PREFIX_PATH "/System/iOSSupport"
30#define DRIVERKIT_PREFIX_PATH "/System/DriverKit"
31
32namespace llvm::MachO {
33
34using PathSeq = std::vector<std::string>;
35
36// Defines simple struct for storing symbolic links.
37struct SymLink {
38 std::string SrcPath;
39 std::string LinkContent;
40
41 SymLink(std::string Path, std::string Link)
42 : SrcPath(std::move(Path)), LinkContent(std::move(Link)) {}
43
45 : SrcPath(std::string(Path)), LinkContent(std::string(Link)) {}
46};
47
48/// Replace extension considering frameworks.
49///
50/// \param Path Location of file.
51/// \param Extension File extension to update with.
53
54/// Determine whether to skip over symlink due to either too many symlink levels
55/// or is cyclic.
56///
57/// \param Path Location to symlink.
58/// \param Result Holds whether to skip over Path.
59std::error_code shouldSkipSymLink(const Twine &Path, bool &Result);
60
61/// Turn absolute symlink into relative.
62///
63/// \param From The symlink.
64/// \param To What the symlink points to.
65/// \param RelativePath Path location to update what the symlink points to.
66std::error_code make_relative(StringRef From, StringRef To,
67 SmallVectorImpl<char> &RelativePath);
68
69/// Determine if library is private by parsing file path.
70/// It does not touch the file system.
71///
72/// \param Path File path for library.
73/// \param IsSymLink Whether path points to a symlink.
74bool isPrivateLibrary(StringRef Path, bool IsSymLink = false);
75
76/// Create a regex rule from provided glob string.
77/// \param Glob String that represents glob input.
78/// \return The equivalent regex rule.
80
81using AliasEntry = std::pair<std::string, EncodeKind>;
82using AliasMap = std::map<AliasEntry, AliasEntry>;
83
84/// Parse input list and capture symbols and their alias.
85///
86/// \param Buffer Data contents of file for the alias list.
87/// \return Lookup table of alias to their base symbol.
88Expected<AliasMap> parseAliasList(std::unique_ptr<llvm::MemoryBuffer> &Buffer);
89
90} // namespace llvm::MachO
91#endif // LLVM_TEXTAPI_UTILS_H
BlockVerifier::State From
Tagged union holding either a T or a Error.
Definition: Error.h:474
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:586
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:50
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:81
std::map< AliasEntry, AliasEntry > AliasMap
Definition: Utils.h:82
std::error_code make_relative(StringRef From, StringRef To, SmallVectorImpl< char > &RelativePath)
Turn absolute symlink into relative.
Definition: Utils.cpp:76
void replace_extension(SmallVectorImpl< char > &Path, const Twine &Extension)
Replace extension considering frameworks.
Definition: Utils.cpp:20
bool isPrivateLibrary(StringRef Path, bool IsSymLink=false)
Determine if library is private by parsing file path.
Definition: Utils.cpp:110
std::vector< std::string > PathSeq
Definition: Utils.h:34
std::pair< std::string, EncodeKind > AliasEntry
Definition: Utils.h:81
llvm::Expected< llvm::Regex > createRegexFromGlob(llvm::StringRef Glob)
Create a regex rule from provided glob string.
Definition: Utils.cpp:160
std::error_code shouldSkipSymLink(const Twine &Path, bool &Result)
Determine whether to skip over symlink due to either too many symlink levels or is cyclic.
Definition: Utils.cpp:44
Expected< AliasMap > parseAliasList(std::unique_ptr< llvm::MemoryBuffer > &Buffer)
Parse input list and capture symbols and their alias.
Definition: Utils.cpp:205
OutputIt move(R &&Range, OutputIt Out)
Provide wrappers to std::move which take ranges instead of having to pass begin/end explicitly.
Definition: STLExtras.h:1849
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:858