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_XCODESDK_H
10#define LLDB_UTILITY_XCODESDK_H
11
13#include "lldb/lldb-forward.h"
14#include "llvm/ADT/StringRef.h"
15#include "llvm/Support/VersionTuple.h"
16#include <tuple>
17
18namespace llvm {
19class Triple;
20}
21
22namespace lldb_private {
23
24/// An abstraction for Xcode-style SDKs that works like \ref ArchSpec.
25class XcodeSDK {
26 std::string m_name;
27
28public:
29 /// Different types of Xcode SDKs.
44 static constexpr int numSDKTypes = Linux + 1;
45
46 /// A parsed SDK directory name.
47 struct Info {
49 llvm::VersionTuple version;
50 bool internal = false;
51
52 Info() = default;
53 bool operator<(const Info &other) const;
54 bool operator==(const Info &other) const;
55 };
56
57
58 /// Default constructor, constructs an empty string.
59 XcodeSDK() = default;
60 /// Construct an XcodeSDK object from a specification.
61 XcodeSDK(Info info);
62 /// Initialize an XcodeSDK object with an SDK name. The SDK name is the last
63 /// directory component of a path one would pass to clang's -isysroot
64 /// parameter. For example, "MacOSX.10.14.sdk".
65 XcodeSDK(std::string &&name) : m_name(std::move(name)) {}
66 static XcodeSDK GetAnyMacOS() { return XcodeSDK("MacOSX.sdk"); }
67
68 /// The merge function follows a strict order to maintain monotonicity:
69 /// 1. SDK with the higher SDKType wins.
70 /// 2. The newer SDK wins.
71 void Merge(const XcodeSDK &other);
72
73 XcodeSDK &operator=(const XcodeSDK &other);
74 XcodeSDK(const XcodeSDK&) = default;
75 bool operator==(const XcodeSDK &other) const;
76
77 /// Return parsed SDK type and version number.
78 Info Parse() const;
79 bool IsAppleInternalSDK() const;
80 llvm::VersionTuple GetVersion() const;
81 Type GetType() const;
82 llvm::StringRef GetString() const;
83
84 /// Whether LLDB feels confident importing Clang modules from this SDK.
85 static bool SDKSupportsModules(Type type, llvm::VersionTuple version);
86 static bool SDKSupportsModules(Type desired_type, const FileSpec &sdk_path);
87
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/// An abstraction which groups an XcodeSDK with the sysroot it was used from.
97///
98/// The sysroot is not necessarily a path to the SDK named by the XcodeSDK: a
99/// compiler may record a sysroot that was remapped, for example with
100/// -fdebug-prefix-map, in which case it is only meaningful verbatim.
104
105public:
106 /// Constructs an empty SDK with no sysroot.
109 : m_sdk(std::move(sdk)), m_sysroot(std::move(sysroot)) {}
110 XcodeSDKAndSysroot(std::string name, FileSpec sysroot)
111 : m_sdk(XcodeSDK(std::move(name))), m_sysroot(std::move(sysroot)) {}
112
113 bool operator==(const XcodeSDKAndSysroot &other) const;
114 bool operator!=(const XcodeSDKAndSysroot &other) const;
115
116 const XcodeSDK &GetSDK() const { return m_sdk; }
117 const FileSpec &GetSysroot() const { return m_sysroot; }
118 llvm::StringRef GetString() const { return m_sdk.GetString(); }
119 XcodeSDK::Type GetType() const { return m_sdk.GetType(); }
120
121 void Merge(const XcodeSDKAndSysroot &other);
122 bool IsAppleInternalSDK() const { return m_sdk.IsAppleInternalSDK(); }
123};
124
125} // namespace lldb_private
126
127#endif
A file utility class.
Definition FileSpec.h:56
An abstraction which groups an XcodeSDK with the sysroot it was used from.
Definition XcodeSDK.h:101
XcodeSDKAndSysroot()=default
Constructs an empty SDK with no sysroot.
llvm::StringRef GetString() const
Definition XcodeSDK.h:118
bool operator==(const XcodeSDKAndSysroot &other) const
Definition XcodeSDK.cpp:332
bool operator!=(const XcodeSDKAndSysroot &other) const
Definition XcodeSDK.cpp:336
const FileSpec & GetSysroot() const
Definition XcodeSDK.h:117
const XcodeSDK & GetSDK() const
Definition XcodeSDK.h:116
XcodeSDKAndSysroot(std::string name, FileSpec sysroot)
Definition XcodeSDK.h:110
XcodeSDK::Type GetType() const
Definition XcodeSDK.h:119
void Merge(const XcodeSDKAndSysroot &other)
Definition XcodeSDK.cpp:312
XcodeSDKAndSysroot(XcodeSDK sdk, FileSpec sysroot)
Definition XcodeSDK.h:108
An abstraction for Xcode-style SDKs that works like ArchSpec.
Definition XcodeSDK.h:25
static constexpr int numSDKTypes
Definition XcodeSDK.h:44
Type
Different types of Xcode SDKs.
Definition XcodeSDK.h:30
static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path)
Definition XcodeSDK.cpp:290
XcodeSDK(const XcodeSDK &)=default
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:66
std::string m_name
Definition XcodeSDK.h:26
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:174
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:65
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:220
A class that represents a running process on the host machine.
A parsed SDK directory name.
Definition XcodeSDK.h:47
llvm::VersionTuple version
Definition XcodeSDK.h:49
bool operator<(const Info &other) const
Definition XcodeSDK.cpp:145
bool operator==(const Info &other) const
Definition XcodeSDK.cpp:150