Coverage Report

Created: 2021-01-19 06:58

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