Coverage Report

Created: 2019-07-24 05:18

/Users/buildslave/jenkins/workspace/clang-stage2-coverage-R/llvm/tools/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
15.6k
driver::parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, StringRef SDKRootPath) {
20
15.6k
  llvm::SmallString<256> Filepath = SDKRootPath;
21
15.6k
  llvm::sys::path::append(Filepath, "SDKSettings.json");
22
15.6k
  llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File =
23
15.6k
      VFS.getBufferForFile(Filepath);
24
15.6k
  if (!File) {
25
10.9k
    // If the file couldn't be read, assume it just doesn't exist.
26
10.9k
    return None;
27
10.9k
  }
28
4.76k
  Expected<llvm::json::Value> Result =
29
4.76k
      llvm::json::parse(File.get()->getBuffer());
30
4.76k
  if (!Result)
31
1
    return Result.takeError();
32
4.76k
33
4.76k
  if (const auto *Obj = Result->getAsObject()) {
34
4.76k
    auto VersionString = Obj->getString("Version");
35
4.76k
    if (VersionString) {
36
4.76k
      VersionTuple Version;
37
4.76k
      if (!Version.tryParse(*VersionString))
38
4.76k
        return DarwinSDKInfo(Version);
39
1
    }
40
4.76k
  }
41
1
  return llvm::make_error<llvm::StringError>("invalid SDKSettings.json",
42
1
                                             llvm::inconvertibleErrorCode());
43
1
}