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 {
25  std::string m_name;
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 {
45  Type type = unknown;
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(XcodeSDK other);
69 
70  XcodeSDK &operator=(XcodeSDK other);
71  XcodeSDK(const XcodeSDK&) = default;
72  bool operator==(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 class that represents a running process on the host machine.
Type
Different types of Xcode SDKs.
Definition: XcodeSDK.h:29
Definition: Debugger.h:49
bool LLDB_API operator==(const SBAddress &lhs, const SBAddress &rhs)
Definition: SBAddress.cpp:66
A file utility class.
Definition: FileSpec.h:56
static XcodeSDK GetAnyMacOS()
Definition: XcodeSDK.h:63
llvm::VersionTuple version
Definition: XcodeSDK.h:46
XcodeSDK(std::string &&name)
Initialize an XcodeSDK object with an SDK name.
Definition: XcodeSDK.h:62
An abstraction for Xcode-style SDKs that works like ArchSpec.
Definition: XcodeSDK.h:24
A parsed SDK directory name.
Definition: XcodeSDK.h:44
std::string m_name
Definition: XcodeSDK.h:25
bool operator<(const Address &lhs, const Address &rhs)
Definition: Address.cpp:955