LLVM 22.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"
18#include "llvm/Support/Error.h"
21#include "llvm/Support/Path.h"
22#include "llvm/Support/Regex.h"
23#include "llvm/TextAPI/Symbol.h"
24#include <map>
25
26#if !defined(PATH_MAX)
27#define PATH_MAX 1024
28#endif // !defined(PATH_MAX)
29
30#define MACCATALYST_PREFIX_PATH "/System/iOSSupport"
31#define DRIVERKIT_PREFIX_PATH "/System/DriverKit"
32
33namespace llvm::MachO {
34
35using PathSeq = std::vector<std::string>;
36using PathToPlatform = std::pair<std::string, std::optional<PlatformType>>;
37using PathToPlatformSeq = std::vector<PathToPlatform>;
38
39// Defines simple struct for storing symbolic links.
40struct SymLink {
41 std::string SrcPath;
42 std::string LinkContent;
43
44 SymLink(std::string Path, std::string Link)
45 : SrcPath(std::move(Path)), LinkContent(std::move(Link)) {}
46
48 : SrcPath(std::string(Path)), LinkContent(std::string(Link)) {}
49};
50
51/// Replace extension considering frameworks.
52///
53/// \param Path Location of file.
54/// \param Extension File extension to update with.
56 const Twine &Extension);
57
58/// Determine whether to skip over symlink due to either too many symlink levels
59/// or is cyclic.
60///
61/// \param Path Location to symlink.
62/// \param Result Holds whether to skip over Path.
63LLVM_ABI std::error_code shouldSkipSymLink(const Twine &Path, bool &Result);
64
65/// Turn absolute symlink into relative.
66///
67/// \param From The symlink.
68/// \param To What the symlink points to.
69/// \param RelativePath Path location to update what the symlink points to.
71 SmallVectorImpl<char> &RelativePath);
72
73/// Determine if library is private by parsing file path.
74/// It does not touch the file system.
75///
76/// \param Path File path for library.
77/// \param IsSymLink Whether path points to a symlink.
78LLVM_ABI bool isPrivateLibrary(StringRef Path, bool IsSymLink = false);
79
80/// Create a regex rule from provided glob string.
81/// \param Glob String that represents glob input.
82/// \return The equivalent regex rule.
84
85using AliasEntry = std::pair<std::string, EncodeKind>;
86using AliasMap = std::map<AliasEntry, AliasEntry>;
87
88/// Parse input list and capture symbols and their alias.
89///
90/// \param Buffer Data contents of file for the alias list.
91/// \return Lookup table of alias to their base symbol.
93parseAliasList(std::unique_ptr<llvm::MemoryBuffer> &Buffer);
94
95/// Pickup active paths for a given platform.
96///
97/// \param Paths File or search paths to pick up.
98/// \param Platform Platform to collect paths for.
100 PlatformType Platform);
101
102} // namespace llvm::MachO
103#endif // LLVM_TEXTAPI_UTILS_H
BlockVerifier::State From
#define LLVM_ABI
Definition: Compiler.h:213
Tagged union holding either a T or a Error.
Definition: Error.h:485
This class consists of common code factored out of the SmallVector class to reduce code duplication b...
Definition: SmallVector.h:574
StringRef - Represent a constant reference to a string, i.e.
Definition: StringRef.h:55
Twine - A lightweight data structure for efficiently representing the concatenation of temporary valu...
Definition: Twine.h:82
std::map< AliasEntry, AliasEntry > AliasMap
Definition: Utils.h:86
LLVM_ABI std::error_code make_relative(StringRef From, StringRef To, SmallVectorImpl< char > &RelativePath)
Turn absolute symlink into relative.
Definition: Utils.cpp:76
PlatformType
Definition: MachO.h:500
LLVM_ABI void replace_extension(SmallVectorImpl< char > &Path, const Twine &Extension)
Replace extension considering frameworks.
Definition: Utils.cpp:20
std::vector< PathToPlatform > PathToPlatformSeq
Definition: Utils.h:37
LLVM_ABI 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:35
std::pair< std::string, EncodeKind > AliasEntry
Definition: Utils.h:85
LLVM_ABI llvm::Expected< llvm::Regex > createRegexFromGlob(llvm::StringRef Glob)
Create a regex rule from provided glob string.
Definition: Utils.cpp:163
LLVM_ABI PathSeq getPathsForPlatform(const PathToPlatformSeq &Paths, PlatformType Platform)
Pickup active paths for a given platform.
Definition: Utils.cpp:239
LLVM_ABI 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
LLVM_ABI Expected< AliasMap > parseAliasList(std::unique_ptr< llvm::MemoryBuffer > &Buffer)
Parse input list and capture symbols and their alias.
Definition: Utils.cpp:208
std::pair< std::string, std::optional< PlatformType > > PathToPlatform
Definition: Utils.h:36
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:1886
Implement std::hash so that hash_code can be used in STL containers.
Definition: BitVector.h:851