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
17namespace llvm {
18class Triple;
19}
20
21namespace lldb_private {
22
23/// An abstraction for Xcode-style SDKs that works like \ref ArchSpec.
24class XcodeSDK {
25 std::string m_name;
26
27public:
28 /// Different types of Xcode SDKs.
29 enum Type : int {
30 MacOSX = 0,
41 unknown = -1
42 };
43 static constexpr int numSDKTypes = Linux + 1;
44
45 /// A parsed SDK directory name.
46 struct Info {
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
89 /// Returns true if the SDK for the specified triple supports
90 /// builtin modules in system headers.
91 ///
92 /// NOTE: should be kept in sync with sdkSupportsBuiltinModules in
93 /// Toolchains/Darwin.cpp
94 ///
95 /// FIXME: this function will be removed once LLDB's ClangExpressionParser
96 /// constructs the compiler instance through the driver/toolchain. See \ref
97 /// SetupImportStdModuleLangOpts
98 ///
99 static bool SDKSupportsBuiltinModules(const llvm::Triple &target_triple,
100 llvm::VersionTuple sdk_version);
101
102 /// Return the canonical SDK name, such as "macosx" for the macOS SDK.
103 static std::string GetCanonicalName(Info info);
104 /// Return the best-matching SDK type for a specific triple.
105 static XcodeSDK::Type GetSDKTypeForTriple(const llvm::Triple &triple);
106
107 static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path);
108};
109
110} // namespace lldb_private
111
112#endif
A file utility class.
Definition: FileSpec.h:56
An abstraction for Xcode-style SDKs that works like ArchSpec.
Definition: XcodeSDK.h:24
static constexpr int numSDKTypes
Definition: XcodeSDK.h:43
bool SupportsSwift() const
Whether this Xcode SDK supports Swift.
Definition: XcodeSDK.cpp:239
Type
Different types of Xcode SDKs.
Definition: XcodeSDK.h:29
static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path)
Definition: XcodeSDK.cpp:330
XcodeSDK(const XcodeSDK &)=default
Type GetType() const
Definition: XcodeSDK.cpp:138
void Merge(const XcodeSDK &other)
The merge function follows a strict order to maintain monotonicity:
Definition: XcodeSDK.cpp:155
XcodeSDK & operator=(const XcodeSDK &other)
XcodeSDK()=default
Default constructor, constructs an empty string.
static XcodeSDK GetAnyMacOS()
Definition: XcodeSDK.h:65
static bool SDKSupportsBuiltinModules(const llvm::Triple &target_triple, llvm::VersionTuple sdk_version)
Returns true if the SDK for the specified triple supports builtin modules in system headers.
Definition: XcodeSDK.cpp:262
std::string m_name
Definition: XcodeSDK.h:25
llvm::VersionTuple GetVersion() const
Definition: XcodeSDK.cpp:132
llvm::StringRef GetString() const
Definition: XcodeSDK.cpp:143
static std::string GetCanonicalName(Info info)
Return the canonical SDK name, such as "macosx" for the macOS SDK.
Definition: XcodeSDK.cpp:170
static XcodeSDK::Type GetSDKTypeForTriple(const llvm::Triple &triple)
Return the best-matching SDK type for a specific triple.
Definition: XcodeSDK.cpp:296
XcodeSDK(std::string &&name)
Initialize an XcodeSDK object with an SDK name.
Definition: XcodeSDK.h:64
Info Parse() const
Return parsed SDK type and version number.
Definition: XcodeSDK.cpp:116
bool operator==(const XcodeSDK &other) const
Definition: XcodeSDK.cpp:63
bool IsAppleInternalSDK() const
Definition: XcodeSDK.cpp:125
static bool SDKSupportsModules(Type type, llvm::VersionTuple version)
Whether LLDB feels confident importing Clang modules from this SDK.
Definition: XcodeSDK.cpp:216
A class that represents a running process on the host machine.
Definition: Debugger.h:54
A parsed SDK directory name.
Definition: XcodeSDK.h:46
llvm::VersionTuple version
Definition: XcodeSDK.h:48
bool operator<(const Info &other) const
Definition: XcodeSDK.cpp:145
bool operator==(const Info &other) const
Definition: XcodeSDK.cpp:150