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,
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
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:41
bool SupportsSwift() const
Whether this Xcode SDK supports Swift.
Definition: XcodeSDK.cpp:222
bool operator==(const XcodeSDK &other)
Definition: XcodeSDK.cpp:59
Type
Different types of Xcode SDKs.
Definition: XcodeSDK.h:29
static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path)
Definition: XcodeSDK.cpp:286
XcodeSDK(const XcodeSDK &)=default
Type GetType() const
Definition: XcodeSDK.cpp:130
void Merge(const XcodeSDK &other)
The merge function follows a strict order to maintain monotonicity:
Definition: XcodeSDK.cpp:147
XcodeSDK & operator=(const XcodeSDK &other)
XcodeSDK()=default
Default constructor, constructs an empty string.
static XcodeSDK GetAnyMacOS()
Definition: XcodeSDK.h:63
std::string m_name
Definition: XcodeSDK.h:25
llvm::VersionTuple GetVersion() const
Definition: XcodeSDK.cpp:124
llvm::StringRef GetString() const
Definition: XcodeSDK.cpp:135
static std::string GetCanonicalName(Info info)
Return the canonical SDK name, such as "macosx" for the macOS SDK.
Definition: XcodeSDK.cpp:162
static XcodeSDK::Type GetSDKTypeForTriple(const llvm::Triple &triple)
Return the best-matching SDK type for a specific triple.
Definition: XcodeSDK.cpp:256
XcodeSDK(std::string &&name)
Initialize an XcodeSDK object with an SDK name.
Definition: XcodeSDK.h:62
Info Parse() const
Return parsed SDK type and version number.
Definition: XcodeSDK.cpp:108
bool IsAppleInternalSDK() const
Definition: XcodeSDK.cpp:117
static bool SDKSupportsModules(Type type, llvm::VersionTuple version)
Whether LLDB feels confident importing Clang modules from this SDK.
Definition: XcodeSDK.cpp:202
A class that represents a running process on the host machine.
Definition: SBAttachInfo.h:14
Definition: Debugger.h:53
A parsed SDK directory name.
Definition: XcodeSDK.h:44
llvm::VersionTuple version
Definition: XcodeSDK.h:46
bool operator<(const Info &other) const
Definition: XcodeSDK.cpp:137
bool operator==(const Info &other) const
Definition: XcodeSDK.cpp:142