1 //===-- XcodeSDK.h ----------------------------------------------*- 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 #ifndef LLDB_UTILITY_SDK_H 10 #define LLDB_UTILITY_SDK_H 11 12 #include "lldb/lldb-forward.h" 13 #include "llvm/ADT/StringRef.h" 14 #include "llvm/Support/VersionTuple.h" 15 #include <tuple> 16 17 namespace llvm { 18 class Triple; 19 } 20 21 namespace lldb_private { 22 23 /// An abstraction for Xcode-style SDKs that works like \ref ArchSpec. 24 class XcodeSDK { 25 std::string m_name; 26 27 public: 28 /// Different types of Xcode SDKs. 29 enum Type : int { 30 MacOSX = 0, 31 iPhoneSimulator, 32 iPhoneOS, 33 AppleTVSimulator, 34 AppleTVOS, 35 WatchSimulator, 36 watchOS, 37 XRSimulator, 38 XROS, 39 bridgeOS, 40 Linux, 41 unknown = -1 42 }; 43 static constexpr int numSDKTypes = Linux + 1; 44 45 /// A parsed SDK directory name. 46 struct Info { 47 Type type = unknown; 48 llvm::VersionTuple version; 49 bool internal = false; 50 51 Info() = default; 52 bool operator<(const Info &other) const; 53 bool operator==(const Info &other) const; 54 }; 55 56 57 /// Default constructor, constructs an empty string. 58 XcodeSDK() = default; 59 /// Construct an XcodeSDK object from a specification. 60 XcodeSDK(Info info); 61 /// Initialize an XcodeSDK object with an SDK name. The SDK name is the last 62 /// directory component of a path one would pass to clang's -isysroot 63 /// parameter. For example, "MacOSX.10.14.sdk". 64 XcodeSDK(std::string &&name) : m_name(std::move(name)) {} 65 static XcodeSDK GetAnyMacOS() { return XcodeSDK("MacOSX.sdk"); } 66 67 /// The merge function follows a strict order to maintain monotonicity: 68 /// 1. SDK with the higher SDKType wins. 69 /// 2. The newer SDK wins. 70 void Merge(const XcodeSDK &other); 71 72 XcodeSDK &operator=(const XcodeSDK &other); 73 XcodeSDK(const XcodeSDK&) = default; 74 bool operator==(const XcodeSDK &other) const; 75 76 /// Return parsed SDK type and version number. 77 Info Parse() const; 78 bool IsAppleInternalSDK() const; 79 llvm::VersionTuple GetVersion() const; 80 Type GetType() const; 81 llvm::StringRef GetString() const; 82 /// Whether this Xcode SDK supports Swift. 83 bool SupportsSwift() const; 84 85 /// Whether LLDB feels confident importing Clang modules from this SDK. 86 static bool SDKSupportsModules(Type type, llvm::VersionTuple version); 87 static bool SDKSupportsModules(Type desired_type, const FileSpec &sdk_path); 88 /// Return the canonical SDK name, such as "macosx" for the macOS SDK. 89 static std::string GetCanonicalName(Info info); 90 /// Return the best-matching SDK type for a specific triple. 91 static XcodeSDK::Type GetSDKTypeForTriple(const llvm::Triple &triple); 92 93 static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path); 94 }; 95 96 } // namespace lldb_private 97 98 #endif 99