forked from apple/swift-clang
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[darwin] parse the SDK settings from SDKSettings.json if it exists and
pass in the -target-sdk-version to the compiler and backend This commit adds support for reading the SDKSettings.json file in the Darwin driver. This file is used by the driver to determine the SDK's version, and it uses that information to pass it down to the compiler using the new -target-sdk-version= option. This option is then used to set the appropriate SDK Version module metadata introduced in r349119. Note: I had to adjust the two ast tests as the SDKROOT environment variable on macOS caused SDK version to be picked up for the compilation of source file but not the AST. rdar://45774000 Differential Revision: https://reviews.llvm.org/D55673 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@349380 91177308-0d34-0410-b5e6-96231b3b80d8
- Loading branch information
Showing
16 changed files
with
256 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
//===--- DarwinSDKInfo.h - SDK Information parser for darwin ----*- C++ -*-===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#ifndef LLVM_CLANG_DRIVER_DARWIN_SDK_INFO_H | ||
#define LLVM_CLANG_DRIVER_DARWIN_SDK_INFO_H | ||
|
||
#include "clang/Basic/LLVM.h" | ||
#include "llvm/Support/Error.h" | ||
#include "llvm/Support/VersionTuple.h" | ||
#include "llvm/Support/VirtualFileSystem.h" | ||
|
||
namespace clang { | ||
namespace driver { | ||
|
||
/// The information about the darwin SDK that was used during this compilation. | ||
class DarwinSDKInfo { | ||
public: | ||
DarwinSDKInfo(llvm::VersionTuple Version) : Version(Version) {} | ||
|
||
const llvm::VersionTuple &getVersion() const { return Version; } | ||
|
||
private: | ||
llvm::VersionTuple Version; | ||
}; | ||
|
||
/// Parse the SDK information from the SDKSettings.json file. | ||
/// | ||
/// \returns an error if the SDKSettings.json file is invalid, None if the | ||
/// SDK has no SDKSettings.json, or a valid \c DarwinSDKInfo otherwise. | ||
Expected<Optional<DarwinSDKInfo>> parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, | ||
StringRef SDKRootPath); | ||
|
||
} // end namespace driver | ||
} // end namespace clang | ||
|
||
#endif // LLVM_CLANG_DRIVER_DARWIN_SDK_INFO_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
//===--- DarwinSDKInfo.cpp - SDK Information parser for darwin - ----------===// | ||
// | ||
// The LLVM Compiler Infrastructure | ||
// | ||
// This file is distributed under the University of Illinois Open Source | ||
// License. See LICENSE.TXT for details. | ||
// | ||
//===----------------------------------------------------------------------===// | ||
|
||
#include "clang/Driver/DarwinSDKInfo.h" | ||
#include "llvm/Support/ErrorOr.h" | ||
#include "llvm/Support/JSON.h" | ||
#include "llvm/Support/MemoryBuffer.h" | ||
#include "llvm/Support/Path.h" | ||
|
||
using namespace clang::driver; | ||
using namespace clang; | ||
|
||
Expected<Optional<DarwinSDKInfo>> | ||
driver::parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, StringRef SDKRootPath) { | ||
llvm::SmallString<256> Filepath = SDKRootPath; | ||
llvm::sys::path::append(Filepath, "SDKSettings.json"); | ||
llvm::ErrorOr<std::unique_ptr<llvm::MemoryBuffer>> File = | ||
VFS.getBufferForFile(Filepath); | ||
if (!File) { | ||
// If the file couldn't be read, assume it just doesn't exist. | ||
return None; | ||
} | ||
Expected<llvm::json::Value> Result = | ||
llvm::json::parse(File.get()->getBuffer()); | ||
if (!Result) | ||
return Result.takeError(); | ||
|
||
if (const auto *Obj = Result->getAsObject()) { | ||
auto VersionString = Obj->getString("Version"); | ||
if (VersionString) { | ||
VersionTuple Version; | ||
if (!Version.tryParse(*VersionString)) | ||
return DarwinSDKInfo(Version); | ||
} | ||
} | ||
return llvm::make_error<llvm::StringError>("invalid SDKSettings.json", | ||
llvm::inconvertibleErrorCode()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
// RUN: %clang_cc1 -triple x86_64-apple-macosx10.14 -target-sdk-version=10.14.1 -emit-llvm -o - %s | FileCheck %s | ||
|
||
// CHECK: !llvm.module.flags = !{!0 | ||
// CHECK: !0 = !{i32 2, !"SDK Version", [3 x i32] [i32 10, i32 14, i32 1]} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{"Version":"10.14"} |
Oops, something went wrong.