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