LLDB  mainline
XcodeSDK.h
Go to the documentation of this file.
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 {
26 
27 public:
28  /// Different types of Xcode SDKs.
29  enum Type : int {
30  MacOSX = 0,
39  unknown = -1
40  };
41  static constexpr int numSDKTypes = Linux + 1;
42 
43  /// A parsed SDK directory name.
44  struct Info {
46  llvm::VersionTuple version;
47  bool internal = false;
48 
49  Info() = default;
50  bool operator<(const Info &other) const;
51  bool operator==(const Info &other) const;
52  };
53 
54 
55  /// Default constructor, constructs an empty string.
56  XcodeSDK() = default;
57  /// Construct an XcodeSDK object from a specification.
58  XcodeSDK(Info info);
59  /// Initialize an XcodeSDK object with an SDK name. The SDK name is the last
60  /// directory component of a path one would pass to clang's -isysroot
61  /// parameter. For example, "MacOSX.10.14.sdk".
62  XcodeSDK(std::string &&name) : m_name(std::move(name)) {}
63  static XcodeSDK GetAnyMacOS() { return XcodeSDK("MacOSX.sdk"); }
64 
65  /// The merge function follows a strict order to maintain monotonicity:
66  /// 1. SDK with the higher SDKType wins.
67  /// 2. The newer SDK wins.
68  void Merge(const XcodeSDK &other);
69 
70  XcodeSDK &operator=(const XcodeSDK &other);
71  XcodeSDK(const XcodeSDK&) = default;
72  bool operator==(const XcodeSDK &other);
73 
74  /// Return parsed SDK type and version number.
75  Info Parse() const;
76  bool IsAppleInternalSDK() const;
77  llvm::VersionTuple GetVersion() const;
78  Type GetType() const;
79  llvm::StringRef GetString() const;
80  /// Whether this Xcode SDK supports Swift.
81  bool SupportsSwift() const;
82 
83  /// Whether LLDB feels confident importing Clang modules from this SDK.
84  static bool SDKSupportsModules(Type type, llvm::VersionTuple version);
85  static bool SDKSupportsModules(Type desired_type, const FileSpec &sdk_path);
86  /// Return the canonical SDK name, such as "macosx" for the macOS SDK.
87  static std::string GetCanonicalName(Info info);
88  /// Return the best-matching SDK type for a specific triple.
89  static XcodeSDK::Type GetSDKTypeForTriple(const llvm::Triple &triple);
90 
91  static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path);
92 };
93 
94 } // namespace lldb_private
95 
96 #endif
lldb_private::XcodeSDK::SupportsSwift
bool SupportsSwift() const
Whether this Xcode SDK supports Swift.
Definition: XcodeSDK.cpp:222
llvm
Definition: Debugger.h:50
lldb_private::XcodeSDK::AppleTVSimulator
@ AppleTVSimulator
Definition: XcodeSDK.h:33
lldb_private::XcodeSDK::GetSDKTypeForTriple
static XcodeSDK::Type GetSDKTypeForTriple(const llvm::Triple &triple)
Return the best-matching SDK type for a specific triple.
Definition: XcodeSDK.cpp:256
lldb_private::XcodeSDK::Merge
void Merge(const XcodeSDK &other)
The merge function follows a strict order to maintain monotonicity:
Definition: XcodeSDK.cpp:147
lldb_private::XcodeSDK::XcodeSDK
XcodeSDK()=default
Default constructor, constructs an empty string.
lldb_private::XcodeSDK::AppleTVOS
@ AppleTVOS
Definition: XcodeSDK.h:34
lldb_private::XcodeSDK::MacOSX
@ MacOSX
Definition: XcodeSDK.h:30
lldb_private::XcodeSDK::iPhoneSimulator
@ iPhoneSimulator
Definition: XcodeSDK.h:31
lldb_private::XcodeSDK
An abstraction for Xcode-style SDKs that works like ArchSpec.
Definition: XcodeSDK.h:24
lldb_private::XcodeSDK::SDKSupportsModules
static bool SDKSupportsModules(Type type, llvm::VersionTuple version)
Whether LLDB feels confident importing Clang modules from this SDK.
Definition: XcodeSDK.cpp:202
lldb_private::XcodeSDK::Parse
Info Parse() const
Return parsed SDK type and version number.
Definition: XcodeSDK.cpp:108
lldb_private::XcodeSDK::GetString
llvm::StringRef GetString() const
Definition: XcodeSDK.cpp:135
lldb_private::XcodeSDK::Info
A parsed SDK directory name.
Definition: XcodeSDK.h:44
lldb_private::XcodeSDK::WatchSimulator
@ WatchSimulator
Definition: XcodeSDK.h:35
lldb_private::XcodeSDK::watchOS
@ watchOS
Definition: XcodeSDK.h:36
lldb_private::XcodeSDK::GetAnyMacOS
static XcodeSDK GetAnyMacOS()
Definition: XcodeSDK.h:63
lldb_private::XcodeSDK::unknown
@ unknown
Definition: XcodeSDK.h:39
lldb_private::FileSpec
Definition: FileSpec.h:55
lldb_private::XcodeSDK::IsAppleInternalSDK
bool IsAppleInternalSDK() const
Definition: XcodeSDK.cpp:117
lldb_private::XcodeSDK::XcodeSDK
XcodeSDK(std::string &&name)
Initialize an XcodeSDK object with an SDK name.
Definition: XcodeSDK.h:62
lldb_private::XcodeSDK::numSDKTypes
static constexpr int numSDKTypes
Definition: XcodeSDK.h:41
lldb_private::XcodeSDK::FindXcodeContentsDirectoryInPath
static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path)
Definition: XcodeSDK.cpp:286
lldb_private::XcodeSDK::Linux
@ Linux
Definition: XcodeSDK.h:38
lldb_private::XcodeSDK::Info::Info
Info()=default
lldb_private::XcodeSDK::operator=
XcodeSDK & operator=(const XcodeSDK &other)
string
string(SUBSTRING ${p} 10 -1 pStripped) if($
Definition: Plugins/CMakeLists.txt:40
lldb_private::XcodeSDK::GetVersion
llvm::VersionTuple GetVersion() const
Definition: XcodeSDK.cpp:124
lldb_private::XcodeSDK::bridgeOS
@ bridgeOS
Definition: XcodeSDK.h:37
lldb_private::XcodeSDK::Info::version
llvm::VersionTuple version
Definition: XcodeSDK.h:46
lldb_private::XcodeSDK::operator==
bool operator==(const XcodeSDK &other)
Definition: XcodeSDK.cpp:59
lldb_private::XcodeSDK::Type
Type
Different types of Xcode SDKs.
Definition: XcodeSDK.h:29
lldb_private::Type
Definition: Type.h:66
lldb_private::XcodeSDK::Info::operator<
bool operator<(const Info &other) const
Definition: XcodeSDK.cpp:137
lldb_private::XcodeSDK::GetCanonicalName
static std::string GetCanonicalName(Info info)
Return the canonical SDK name, such as "macosx" for the macOS SDK.
Definition: XcodeSDK.cpp:162
lldb_private::XcodeSDK::m_name
std::string m_name
Definition: XcodeSDK.h:25
lldb-forward.h
lldb_private::XcodeSDK::Info::type
Type type
Definition: XcodeSDK.h:45
lldb_private::XcodeSDK::Info::operator==
bool operator==(const Info &other) const
Definition: XcodeSDK.cpp:142
lldb_private
A class that represents a running process on the host machine.
Definition: SBCommandInterpreterRunOptions.h:16
lldb_private::XcodeSDK::GetType
Type GetType() const
Definition: XcodeSDK.cpp:130
lldb_private::XcodeSDK::iPhoneOS
@ iPhoneOS
Definition: XcodeSDK.h:32