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>;
35using PathToPlatform = std::pair<std::string, std::optional<PlatformType>>;
36using PathToPlatformSeq = std::vector<PathToPlatform>;
37
38// Defines simple struct for storing symbolic links.
39struct SymLink {
40 std::string SrcPath;
41 std::string LinkContent;
42
43 SymLink(std::string Path, std::string Link)
44 : SrcPath(std::move(Path)), LinkContent(std::move(Link)) {}
45
47 : SrcPath(std::string(Path)), LinkContent(std::string(Link)) {}
48};
49
50/// Replace extension considering frameworks.
51///
52/// \param Path Location of file.
53/// \param Extension File extension to update with.
55
56/// Determine whether to skip over symlink due to either too many symlink levels
57/// or is cyclic.
58///
59/// \param Path Location to symlink.
60/// \param Result Holds whether to skip over Path.
61std::error_code shouldSkipSymLink(const Twine &Path, bool &Result);
62
63/// Turn absolute symlink into relative.
64///
65/// \param From The symlink.
66/// \param To What the symlink points to.
67/// \param RelativePath Path location to update what the symlink points to.
68std::error_code make_relative(StringRef From, StringRef To,
69 SmallVectorImpl<char> &RelativePath);
70
71/// Determine if library is private by parsing file path.
72/// It does not touch the file system.
73///
74/// \param Path File path for library.
75/// \param IsSymLink Whether path points to a symlink.
76bool isPrivateLibrary(StringRef Path, bool IsSymLink = false);
77
78/// Create a regex rule from provided glob string.
79/// \param Glob String that represents glob input.
80/// \return The equivalent regex rule.
82
83using AliasEntry = std::pair<std::string, EncodeKind>;
84using AliasMap = std::map<AliasEntry, AliasEntry>;
85
86/// Parse input list and capture symbols and their alias.
87///
88/// \param Buffer Data contents of file for the alias list.
89/// \return Lookup table of alias to their base symbol.
90Expected<AliasMap> parseAliasList(std::unique_ptr<llvm::MemoryBuffer> &Buffer);
91
92/// Pickup active paths for a given platform.
93///
94/// \param Paths File or search paths to pick up.
95/// \param Platform Platform to collect paths for.
97 PlatformType Platform);
98
99} // namespace llvm::MachO
100#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:84
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
void replace_extension(SmallVectorImpl< char > &Path, const Twine &Extension)
Replace extension considering frameworks.
Definition: Utils.cpp:20
std::vector< PathToPlatform > PathToPlatformSeq
Definition: Utils.h:36
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:83
llvm::Expected< llvm::Regex > createRegexFromGlob(llvm::StringRef Glob)
Create a regex rule from provided glob string.
Definition: Utils.cpp:160
PathSeq getPathsForPlatform(const PathToPlatformSeq &Paths, PlatformType Platform)
Pickup active paths for a given platform.
Definition: Utils.cpp:236
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
std::pair< std::string, std::optional< PlatformType > > PathToPlatform
Definition: Utils.h:35
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