Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-05-10 08:42:59

0001 //===-- XcodeSDK.h ----------------------------------------------*- C++ -*-===//
0002 //
0003 // Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
0004 // See https://llvm.org/LICENSE.txt for license information.
0005 // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
0006 //
0007 //===----------------------------------------------------------------------===//
0008 
0009 #ifndef LLDB_UTILITY_SDK_H
0010 #define LLDB_UTILITY_SDK_H
0011 
0012 #include "lldb/lldb-forward.h"
0013 #include "llvm/ADT/StringRef.h"
0014 #include "llvm/Support/VersionTuple.h"
0015 #include <tuple>
0016 
0017 namespace llvm {
0018 class Triple;
0019 }
0020 
0021 namespace lldb_private {
0022 
0023 /// An abstraction for Xcode-style SDKs that works like \ref ArchSpec.
0024 class XcodeSDK {
0025   std::string m_name;
0026 
0027 public:
0028   /// Different types of Xcode SDKs.
0029   enum Type : int {
0030     MacOSX = 0,
0031     iPhoneSimulator,
0032     iPhoneOS,
0033     AppleTVSimulator,
0034     AppleTVOS,
0035     WatchSimulator,
0036     watchOS,
0037     XRSimulator,
0038     XROS,
0039     bridgeOS,
0040     Linux,
0041     unknown = -1
0042   };
0043   static constexpr int numSDKTypes = Linux + 1;
0044 
0045   /// A parsed SDK directory name.
0046   struct Info {
0047     Type type = unknown;
0048     llvm::VersionTuple version;
0049     bool internal = false;
0050 
0051     Info() = default;
0052     bool operator<(const Info &other) const;
0053     bool operator==(const Info &other) const;
0054   };
0055 
0056 
0057   /// Default constructor, constructs an empty string.
0058   XcodeSDK() = default;
0059   /// Construct an XcodeSDK object from a specification.
0060   XcodeSDK(Info info);
0061   /// Initialize an XcodeSDK object with an SDK name. The SDK name is the last
0062   /// directory component of a path one would pass to clang's -isysroot
0063   /// parameter. For example, "MacOSX.10.14.sdk".
0064   XcodeSDK(std::string &&name) : m_name(std::move(name)) {}
0065   static XcodeSDK GetAnyMacOS() { return XcodeSDK("MacOSX.sdk"); }
0066 
0067   /// The merge function follows a strict order to maintain monotonicity:
0068   /// 1. SDK with the higher SDKType wins.
0069   /// 2. The newer SDK wins.
0070   void Merge(const XcodeSDK &other);
0071 
0072   XcodeSDK &operator=(const XcodeSDK &other);
0073   XcodeSDK(const XcodeSDK&) = default;
0074   bool operator==(const XcodeSDK &other) const;
0075 
0076   /// Return parsed SDK type and version number.
0077   Info Parse() const;
0078   bool IsAppleInternalSDK() const;
0079   llvm::VersionTuple GetVersion() const;
0080   Type GetType() const;
0081   llvm::StringRef GetString() const;
0082   /// Whether this Xcode SDK supports Swift.
0083   bool SupportsSwift() const;
0084 
0085   /// Whether LLDB feels confident importing Clang modules from this SDK.
0086   static bool SDKSupportsModules(Type type, llvm::VersionTuple version);
0087   static bool SDKSupportsModules(Type desired_type, const FileSpec &sdk_path);
0088 
0089   /// Returns true if the SDK for the specified triple supports
0090   /// builtin modules in system headers.
0091   ///
0092   /// NOTE: should be kept in sync with sdkSupportsBuiltinModules in
0093   /// Toolchains/Darwin.cpp
0094   ///
0095   /// FIXME: this function will be removed once LLDB's ClangExpressionParser
0096   /// constructs the compiler instance through the driver/toolchain. See \ref
0097   /// SetupImportStdModuleLangOpts
0098   ///
0099   static bool SDKSupportsBuiltinModules(const llvm::Triple &target_triple,
0100                                         llvm::VersionTuple sdk_version);
0101 
0102   /// Return the canonical SDK name, such as "macosx" for the macOS SDK.
0103   static std::string GetCanonicalName(Info info);
0104   /// Return the best-matching SDK type for a specific triple.
0105   static XcodeSDK::Type GetSDKTypeForTriple(const llvm::Triple &triple);
0106 
0107   static std::string FindXcodeContentsDirectoryInPath(llvm::StringRef path);
0108 };
0109 
0110 } // namespace lldb_private
0111 
0112 #endif