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 std::string FilePath, llvm::Triple::OSType OS,
185 llvm::Triple::EnvironmentType Environment, VersionTuple Version,
186 VersionTuple MaximumDeploymentTarget,
189 std::optional<RelatedTargetVersionMapping>>
192 std::optional<RelatedTargetVersionMapping>>())
193 : FilePath(FilePath), OS(OS), Environment(Environment), Version(Version),
194 MaximumDeploymentTarget(MaximumDeploymentTarget),
195 PlatformInfos(
std::move(PlatformInfos)),
196 VersionMappings(
std::move(VersionMappings)) {}
200 llvm::Triple::OSType
getOS()
const {
return OS; }
204 const llvm::VersionTuple &
getVersion()
const {
return Version; }
207 return PlatformInfos[0];
211 auto PlatformInfoIt = llvm::find(PlatformInfos, Triple);
212 if (PlatformInfoIt == PlatformInfos.end())
214 return PlatformInfoIt->getPlatformPrefix();
229 auto Mapping = VersionMappings.find(Kind.Value);
230 if (Mapping == VersionMappings.end())
232 return Mapping->getSecond() ? &*Mapping->getSecond() :
nullptr;
235 static std::optional<DarwinSDKInfo>
237 const llvm::json::Object *Obj);
240 std::string FilePath;
241 llvm::Triple::OSType OS;
242 llvm::Triple::EnvironmentType Environment;
243 VersionTuple Version;
244 VersionTuple MaximumDeploymentTarget;
250 std::optional<RelatedTargetVersionMapping>>
Forward-declares and imports various common LLVM datatypes that clang wants to use unqualified.
static std::optional< DarwinSDKInfo > parseDarwinSDKSettingsJSON(std::string FilePath, const llvm::json::Object *Obj)
SmallVector< SDKPlatformInfo, 2 > PlatformInfoStorageType
const RelatedTargetVersionMapping * getVersionMapping(OSEnvPair Kind) const
const SDKPlatformInfo & getCanonicalPlatformInfo() const
StringRef getFilePath() const
DarwinSDKInfo(std::string FilePath, llvm::Triple::OSType OS, llvm::Triple::EnvironmentType Environment, VersionTuple Version, VersionTuple MaximumDeploymentTarget, PlatformInfoStorageType PlatformInfos, llvm::DenseMap< OSEnvPair::StorageType, std::optional< RelatedTargetVersionMapping > > VersionMappings=llvm::DenseMap< OSEnvPair::StorageType, std::optional< RelatedTargetVersionMapping > >())
const StringRef getPlatformPrefix(llvm::Triple Triple) const
llvm::Triple::EnvironmentType getEnvironment() const
const llvm::VersionTuple & getVersion() const
llvm::Triple::OSType getOS() const
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