clang  8.0.0
DarwinSDKInfo.cpp
Go to the documentation of this file.
1 //===--- DarwinSDKInfo.cpp - SDK Information parser for darwin - ----------===//
2 //
3 // The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
11 #include "llvm/Support/ErrorOr.h"
12 #include "llvm/Support/JSON.h"
13 #include "llvm/Support/MemoryBuffer.h"
14 #include "llvm/Support/Path.h"
15 
16 using namespace clang::driver;
17 using namespace clang;
18 
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);
25  if (!File) {
26  // If the file couldn't be read, assume it just doesn't exist.
27  return None;
28  }
30  llvm::json::parse(File.get()->getBuffer());
31  if (!Result)
32  return Result.takeError();
33 
34  if (const auto *Obj = Result->getAsObject()) {
35  auto VersionString = Obj->getString("Version");
36  if (VersionString) {
37  VersionTuple Version;
38  if (!Version.tryParse(*VersionString))
39  return DarwinSDKInfo(Version);
40  }
41  }
42  return llvm::make_error<llvm::StringError>("invalid SDKSettings.json",
43  llvm::inconvertibleErrorCode());
44 }
The information about the darwin SDK that was used during this compilation.
Definition: DarwinSDKInfo.h:22
Expected< Optional< DarwinSDKInfo > > parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, StringRef SDKRootPath)
Parse the SDK information from the SDKSettings.json file.
Dataflow Directional Tag Classes.