10#include "llvm/Support/ErrorOr.h"
11#include "llvm/Support/JSON.h"
12#include "llvm/Support/MemoryBuffer.h"
13#include "llvm/Support/Path.h"
19 const VersionTuple &Key,
const VersionTuple &MinimumValue,
20 std::optional<VersionTuple> MaximumValue)
const {
21 if (Key < MinimumKeyVersion)
23 if (Key > MaximumKeyVersion)
25 auto KV = Mapping.find(Key.normalize());
26 if (KV != Mapping.end())
27 return KV->getSecond();
32 return map(VersionTuple(Key.getMajor()), MinimumValue, MaximumValue);
37std::optional<DarwinSDKInfo::RelatedTargetVersionMapping>
39 const llvm::json::Object &Obj, VersionTuple MaximumDeploymentTarget) {
40 VersionTuple
Min = VersionTuple(std::numeric_limits<unsigned>::max());
41 VersionTuple
Max = VersionTuple(0);
42 VersionTuple MinValue =
Min;
43 llvm::DenseMap<VersionTuple, VersionTuple> Mapping;
44 for (
const auto &KV : Obj) {
45 if (
auto Val = KV.getSecond().getAsString()) {
46 llvm::VersionTuple KeyVersion;
47 llvm::VersionTuple ValueVersion;
48 if (KeyVersion.tryParse(KV.getFirst()) || ValueVersion.tryParse(*Val))
50 Mapping[KeyVersion.normalize()] = ValueVersion;
55 if (ValueVersion < MinValue)
56 MinValue = ValueVersion;
62 Min,
Max, MinValue, MaximumDeploymentTarget, std::move(Mapping));
65static std::optional<VersionTuple>
getVersionKey(
const llvm::json::Object &Obj,
67 auto Value = Obj.getString(Key);
71 if (Version.tryParse(*
Value))
76std::optional<DarwinSDKInfo>
81 auto MaximumDeploymentVersion =
83 if (!MaximumDeploymentVersion)
86 std::optional<RelatedTargetVersionMapping>>
88 if (
const auto *VM = Obj->getObject(
"VersionMap")) {
91 for (
const auto &KV : *VM) {
92 auto Pair = StringRef(KV.getFirst()).split(
"_");
93 if (Pair.first.compare_insensitive(
"ios") == 0) {
94 llvm::Triple TT(llvm::Twine(
"--") + Pair.second.lower());
95 if (TT.getOS() != llvm::Triple::UnknownOS) {
97 *KV.getSecond().getAsObject(), *MaximumDeploymentVersion);
99 VersionMappings[
OSEnvPair(llvm::Triple::IOS,
100 llvm::Triple::UnknownEnvironment,
102 llvm::Triple::UnknownEnvironment)
103 .Value] = std::move(Mapping);
108 if (
const auto *Mapping = VM->getObject(
"macOS_iOSMac")) {
110 *Mapping, *MaximumDeploymentVersion);
114 std::move(VersionMap);
116 if (
const auto *Mapping = VM->getObject(
"iOSMac_macOS")) {
118 *Mapping, *MaximumDeploymentVersion);
122 std::move(VersionMap);
127 std::move(*MaximumDeploymentVersion),
128 std::move(VersionMappings));
134 llvm::sys::path::append(Filepath,
"SDKSettings.json");
135 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>>
File =
136 VFS.getBufferForFile(Filepath);
142 llvm::json::parse(
File.get()->getBuffer());
144 return Result.takeError();
146 if (
const auto *Obj =
Result->getAsObject()) {
148 return std::move(SDKInfo);
150 return llvm::make_error<llvm::StringError>(
"invalid SDKSettings.json",
151 llvm::inconvertibleErrorCode());
static std::optional< VersionTuple > getVersionKey(const llvm::json::Object &Obj, StringRef Key)
The information about the darwin SDK that was used during this compilation.
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.
@ Result
The result type of a method or function.
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...