1 //===--- DarwinSDKInfo.cpp - SDK Information parser for darwin - ----------===//
3 // The LLVM Compiler Infrastructure
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
8 //===----------------------------------------------------------------------===//
10 #include "clang/Driver/DarwinSDKInfo.h"
11 #include "llvm/Support/ErrorOr.h"
12 #include "llvm/Support/JSON.h"
13 #include "llvm/Support/MemoryBuffer.h"
14 #include "llvm/Support/Path.h"
16 using namespace clang::driver;
17 using namespace clang;
19 Expected<Optional<DarwinSDKInfo>>
20 driver::parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, StringRef SDKRootPath) {
21 llvm::SmallString<256> Filepath = SDKRootPath;
22 llvm::sys::path::append(Filepath, "SDKSettings.json");
23 llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File =
24 VFS.getBufferForFile(Filepath);
26 // If the file couldn't be read, assume it just doesn't exist.
29 Expected<llvm::json::Value> Result =
30 llvm::json::parse(File.get()->getBuffer());
32 return Result.takeError();
34 if (const auto *Obj = Result->getAsObject()) {
35 auto VersionString = Obj->getString("Version");
38 if (!Version.tryParse(*VersionString))
39 return DarwinSDKInfo(Version);
42 return llvm::make_error<llvm::StringError>("invalid SDKSettings.json",
43 llvm::inconvertibleErrorCode());