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
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;
28
29public:
30 /// Different types of Xcode SDKs.
45 static constexpr int numSDKTypes = Linux + 1;
46
47 /// A parsed SDK directory name.
48 struct Info {
50 llvm::VersionTuple version;
51 bool internal = false;
52
53 Info() = default;
54 bool operator<(const Info &other) const;
55 bool operator==(const Info &other) const;
56 };
57
58
59 /// Default constructor, constructs an empty string.
60 XcodeSDK() = default;
61 /// Construct an XcodeSDK object from a specification.
62 XcodeSDK(Info info);
63 /// Initialize an XcodeSDK object with an SDK name. The SDK name is the last
64 /// directory component of a path one would pass to clang's -isysroot
65 /// parameter. For example, "MacOSX.10.14.sdk".
66 XcodeSDK(std::string &&name) : m_name(std::move(name)) {}
67 XcodeSDK(std::string name, FileSpec sysroot)
68 : m_name(std::move(name)), m_sysroot(std::move(sysroot)) {
69 assert(!m_sysroot || m_name == m_sysroot.GetFilename().GetStringRef());
70 }
71 static XcodeSDK GetAnyMacOS() { return XcodeSDK("MacOSX.sdk"); }
72
73 /// The merge function follows a strict order to maintain monotonicity:
74 /// 1. SDK with the higher SDKType wins.
75 /// 2. The newer SDK wins.
76 void Merge(const XcodeSDK &other);
77
78 XcodeSDK &operator=(const XcodeSDK &other);
79 XcodeSDK(const XcodeSDK&) = default;
80 bool operator==(const XcodeSDK &other) const;
81
82 /// Return parsed SDK type and version number.
83 Info Parse() const;
84 bool IsAppleInternalSDK() const;
85 llvm::VersionTuple GetVersion() const;
86 Type GetType() const;
87 llvm::StringRef GetString() const;
88 const FileSpec &GetSysroot() const;
89
90 /// Whether LLDB feels confident importing Clang modules from this SDK.
91 static bool SDKSupportsModules(Type type, llvm::VersionTuple version);
92 static bool SDKSupportsModules(Type desired_type, const FileSpec &sdk_path);
93
94 /// Return the canonical SDK name, such as "macosx" for the macOS SDK.
95 static std::string GetCanonicalName(Info info);
96 /// Return the best-matching SDK type for a specific triple.
97 static XcodeSDK::Type GetSDKTypeForTriple(const llvm::Triple &triple);
98
99 static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path);
100};
101
102} // namespace lldb_private
103
104#endif
A file utility class.
Definition FileSpec.h:57
An abstraction for Xcode-style SDKs that works like ArchSpec.
Definition XcodeSDK.h:25
static constexpr int numSDKTypes
Definition XcodeSDK.h:45
Type
Different types of Xcode SDKs.
Definition XcodeSDK.h:31
static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path)
Definition XcodeSDK.cpp:293
XcodeSDK(std::string name, FileSpec sysroot)
Definition XcodeSDK.h:67
const FileSpec & GetSysroot() const
Definition XcodeSDK.cpp:145
XcodeSDK(const XcodeSDK &)=default
void Merge(const XcodeSDK &other)
The merge function follows a strict order to maintain monotonicity:
Definition XcodeSDK.cpp:157
XcodeSDK & operator=(const XcodeSDK &other)
XcodeSDK()=default
Default constructor, constructs an empty string.
static XcodeSDK GetAnyMacOS()
Definition XcodeSDK.h:71
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:177
static XcodeSDK::Type GetSDKTypeForTriple(const llvm::Triple &triple)
Return the best-matching SDK type for a specific triple.
Definition XcodeSDK.cpp:259
XcodeSDK(std::string &&name)
Initialize an XcodeSDK object with an SDK name.
Definition XcodeSDK.h:66
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:223
A class that represents a running process on the host machine.
A parsed SDK directory name.
Definition XcodeSDK.h:48
llvm::VersionTuple version
Definition XcodeSDK.h:50
bool operator<(const Info &other) const
Definition XcodeSDK.cpp:147
bool operator==(const Info &other) const
Definition XcodeSDK.cpp:152