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"
19#include "llvm/Support/Path.h"
20#include "llvm/Support/Regex.h"
21
22#if !defined(PATH_MAX)
23#define PATH_MAX 1024
24#endif // !defined(PATH_MAX)
25
26#define MACCATALYST_PREFIX_PATH "/System/iOSSupport"
27#define DRIVERKIT_PREFIX_PATH "/System/DriverKit"
28
29namespace llvm::MachO {
30
31using PathSeq = std::vector<std::string>;
32
33// Defines simple struct for storing symbolic links.
34struct SymLink {
35 std::string SrcPath;
36 std::string LinkContent;
37
38 SymLink(std::string Path, std::string Link)
39 : SrcPath(std::move(Path)), LinkContent(std::move(Link)) {}
40
42 : SrcPath(std::string(Path)), LinkContent(std::string(Link)) {}
43};
44
45/// Replace extension considering frameworks.
46///
47/// \param Path Location of file.
48/// \param Extension File extension to update with.
50
51/// Determine whether to skip over symlink due to either too many symlink levels
52/// or is cyclic.
53///
54/// \param Path Location to symlink.
55/// \param Result Holds whether to skip over Path.
56std::error_code shouldSkipSymLink(const Twine &Path, bool &Result);
57
58/// Turn absolute symlink into relative.
59///
60/// \param From The symlink.
61/// \param To What the symlink points to.
62/// \param RelativePath Path location to update what the symlink points to.
63std::error_code make_relative(StringRef From, StringRef To,
64 SmallVectorImpl<char> &RelativePath);
65
66/// Determine if library is private by parsing file path.
67/// It does not touch the file system.
68///
69/// \param Path File path for library.
70/// \param IsSymLink Whether path points to a symlink.
71bool isPrivateLibrary(StringRef Path, bool IsSymLink = false);
72
73/// Create a regex rule from provided glob string.
74/// \param Glob String that represents glob input.
75/// \return The equivalent regex rule.
77
78} // namespace llvm::MachO
79#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::error_code make_relative(StringRef From, StringRef To, SmallVectorImpl< char > &RelativePath)
Turn absolute symlink into relative.
Definition: Utils.cpp:74
void replace_extension(SmallVectorImpl< char > &Path, const Twine &Extension)
Replace extension considering frameworks.
Definition: Utils.cpp:18
bool isPrivateLibrary(StringRef Path, bool IsSymLink=false)
Determine if library is private by parsing file path.
Definition: Utils.cpp:108
std::vector< std::string > PathSeq
Definition: Utils.h:31
llvm::Expected< llvm::Regex > createRegexFromGlob(llvm::StringRef Glob)
Create a regex rule from provided glob string.
Definition: Utils.cpp:158
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:42
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