Coverage Report

Created: 2020-02-15 09:57

/Users/buildslave/jenkins/workspace/coverage/llvm-project/clang/lib/Driver/DarwinSDKInfo.cpp
Line
Count
Source
1
//===--- DarwinSDKInfo.cpp - SDK Information parser for darwin - ----------===//
2
//
3
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
4
// See https://llvm.org/LICENSE.txt for license information.
5
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
6
//
7
//===----------------------------------------------------------------------===//
8
9
#include "clang/Driver/DarwinSDKInfo.h"
10
#include "llvm/Support/ErrorOr.h"
11
#include "llvm/Support/JSON.h"
12
#include "llvm/Support/MemoryBuffer.h"
13
#include "llvm/Support/Path.h"
14
15
using namespace clang::driver;
16
using namespace clang;
17
18
Expected<Optional<DarwinSDKInfo>>
19
11.2k
driver::parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, StringRef SDKRootPath) {
20
11.2k
  llvm::SmallString<256> Filepath = SDKRootPath;
21
11.2k
  llvm::sys::path::append(Filepath, "SDKSettings.json");
22
11.2k
  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File =
23
11.2k
      VFS.getBufferForFile(Filepath);
24
11.2k
  if (!File) {
25
91
    // If the file couldn't be read, assume it just doesn't exist.
26
91
    return None;
27
91
  }
28
11.2k
  Expected<llvm::json::Value> Result =
29
11.2k
      llvm::json::parse(File.get()->getBuffer());
30
11.2k
  if (!Result)
31
1
    return Result.takeError();
32
11.2k
33
11.2k
  if (const auto *Obj = Result->getAsObject()) {
34
11.2k
    auto VersionString = Obj->getString("Version");
35
11.2k
    if (VersionString) {
36
11.2k
      VersionTuple Version;
37
11.2k
      if (!Version.tryParse(*VersionString))
38
11.2k
        return DarwinSDKInfo(Version);
39
1
    }
40
11.2k
  }
41
1
  return llvm::make_error<llvm::StringError>("invalid SDKSettings.json",
42
1
                                             llvm::inconvertibleErrorCode());
43
1
}