Coverage Report

Created: 2022-01-15 10:30

/Users/buildslave/jenkins/workspace/coverage/llvm-project/lldb/include/lldb/Utility/XcodeSDK.h
Line
Count
Source
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,
31
    iPhoneSimulator,
32
    iPhoneOS,
33
    AppleTVSimulator,
34
    AppleTVOS,
35
    WatchSimulator,
36
    watchOS,
37
    bridgeOS,
38
    Linux,
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
536
    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
3
  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
691
  XcodeSDK(std::string &&name) : m_name(std::move(name)) {}
63
454
  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
500
  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