9#ifndef LLVM_CLANG_BASIC_DARWINSDKINFO_H
10#define LLVM_CLANG_BASIC_DARWINSDKINFO_H
13#include "llvm/ADT/DenseMap.h"
14#include "llvm/ADT/STLExtras.h"
15#include "llvm/ADT/SmallVector.h"
16#include "llvm/ADT/StringRef.h"
17#include "llvm/Support/Error.h"
18#include "llvm/Support/VersionTuple.h"
19#include "llvm/Support/VirtualFileSystem.h"
20#include "llvm/TargetParser/Triple.h"
40 llvm::Triple::EnvironmentType Environment,
41 llvm::Triple::ObjectFormatType ObjectFormat,
42 StringRef PlatformPrefix)
43 : Vendor(Vendor), OS(OS), Environment(Environment),
44 ObjectFormat(ObjectFormat), PlatformPrefix(PlatformPrefix) {}
46 llvm::Triple::VendorType
getVendor()
const {
return Vendor; }
47 llvm::Triple::OSType
getOS()
const {
return OS; }
55 return (Vendor == RHS.getVendor()) && (OS == RHS.getOS()) &&
56 (Environment == RHS.getEnvironment()) &&
57 (ObjectFormat == RHS.getObjectFormat());
61 llvm::Triple::VendorType Vendor;
62 llvm::Triple::OSType OS;
63 llvm::Triple::EnvironmentType Environment;
64 llvm::Triple::ObjectFormatType ObjectFormat;
65 std::string PlatformPrefix;
75 llvm::Triple::EnvironmentType FromEnv,
76 llvm::Triple::OSType ToOS,
77 llvm::Triple::EnvironmentType ToEnv)
87 return OSEnvPair(llvm::Triple::MacOSX, llvm::Triple::UnknownEnvironment,
88 llvm::Triple::IOS, llvm::Triple::MacABI);
94 return OSEnvPair(llvm::Triple::IOS, llvm::Triple::MacABI,
95 llvm::Triple::MacOSX, llvm::Triple::UnknownEnvironment);
101 return OSEnvPair(llvm::Triple::IOS, llvm::Triple::UnknownEnvironment,
102 llvm::Triple::WatchOS, llvm::Triple::UnknownEnvironment);
108 return OSEnvPair(llvm::Triple::IOS, llvm::Triple::UnknownEnvironment,
109 llvm::Triple::TvOS, llvm::Triple::UnknownEnvironment);
126 VersionTuple MinimumKeyVersion, VersionTuple MaximumKeyVersion,
127 VersionTuple MinimumValue, VersionTuple MaximumValue,
128 llvm::DenseMap<VersionTuple, VersionTuple> Mapping)
129 : MinimumKeyVersion(MinimumKeyVersion),
130 MaximumKeyVersion(MaximumKeyVersion), MinimumValue(MinimumValue),
131 MaximumValue(MaximumValue), Mapping(Mapping) {
132 assert(!this->Mapping.empty() &&
"unexpected empty mapping");
141 std::optional<VersionTuple>
142 map(
const VersionTuple &Key,
const VersionTuple &MinimumValue,
143 std::optional<VersionTuple> MaximumValue)
const;
148 std::optional<VersionTuple>
151 if (Key.getMajor() == 100000)
152 return VersionTuple(100000);
154 return map(Key, MinimumValue, std::nullopt);
161 std::optional<VersionTuple>
164 if (Key.getMajor() == 100000)
165 return VersionTuple(100000);
166 return map(Key, MinimumValue, MaximumValue);
169 static std::optional<RelatedTargetVersionMapping>
171 VersionTuple MaximumDeploymentTarget);
174 VersionTuple MinimumKeyVersion;
175 VersionTuple MaximumKeyVersion;
176 VersionTuple MinimumValue;
177 VersionTuple MaximumValue;
178 llvm::DenseMap<VersionTuple, VersionTuple> Mapping;
184 VersionTuple Version, VersionTuple MaximumDeploymentTarget,
187 std::optional<RelatedTargetVersionMapping>>
190 std::optional<RelatedTargetVersionMapping>>())
191 : Version(Version), MaximumDeploymentTarget(MaximumDeploymentTarget),
192 PlatformInfos(
std::move(PlatformInfos)),
193 VersionMappings(
std::move(VersionMappings)) {}
195 const llvm::VersionTuple &
getVersion()
const {
return Version; }
198 return PlatformInfos[0];
202 auto PlatformInfoIt = llvm::find(PlatformInfos, Triple);
203 if (PlatformInfoIt == PlatformInfos.end())
205 return PlatformInfoIt->getPlatformPrefix();
220 auto Mapping = VersionMappings.find(Kind.Value);
221 if (Mapping == VersionMappings.end())
223 return Mapping->getSecond() ? &*Mapping->getSecond() :
nullptr;
226 static std::optional<DarwinSDKInfo>
230 VersionTuple Version;
231 VersionTuple MaximumDeploymentTarget;
237 std::optional<RelatedTargetVersionMapping>>
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
SmallVector< SDKPlatformInfo, 2 > PlatformInfoStorageType
const RelatedTargetVersionMapping * getVersionMapping(OSEnvPair Kind) const
const SDKPlatformInfo & getCanonicalPlatformInfo() const
const StringRef getPlatformPrefix(llvm::Triple Triple) const
DarwinSDKInfo(VersionTuple Version, VersionTuple MaximumDeploymentTarget, PlatformInfoStorageType PlatformInfos, llvm::DenseMap< OSEnvPair::StorageType, std::optional< RelatedTargetVersionMapping > > VersionMappings=llvm::DenseMap< OSEnvPair::StorageType, std::optional< RelatedTargetVersionMapping > >())
const llvm::VersionTuple & getVersion() const
static std::optional< DarwinSDKInfo > parseDarwinSDKSettingsJSON(const llvm::json::Object *Obj)
The JSON file list parser is used to communicate input to InstallAPI.
Expected< std::optional< DarwinSDKInfo > > parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, StringRef SDKRootPath)
Parse the SDK information from the SDKSettings.json file.
Diagnostic wrappers for TextAPI types for error reporting.
A value that describes two os-environment pairs that can be used as a key to the version map in the S...
static constexpr OSEnvPair macCatalystToMacOSPair()
Returns the os-environment mapping pair that's used to represent the Mac Catalyst -> macOS version ma...
static constexpr OSEnvPair macOStoMacCatalystPair()
Returns the os-environment mapping pair that's used to represent the macOS -> Mac Catalyst version ma...
static constexpr OSEnvPair iOStoWatchOSPair()
Returns the os-environment mapping pair that's used to represent the iOS -> watchOS version mapping.
static constexpr OSEnvPair iOStoTvOSPair()
Returns the os-environment mapping pair that's used to represent the iOS -> tvOS version mapping.
constexpr OSEnvPair(llvm::Triple::OSType FromOS, llvm::Triple::EnvironmentType FromEnv, llvm::Triple::OSType ToOS, llvm::Triple::EnvironmentType ToEnv)
friend class DarwinSDKInfo