Skip to content

Upstream macCatalyst driver #534

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions clang/include/clang/Basic/DiagnosticDriverKinds.td
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,8 @@ def warn_invalid_ios_deployment_target : Warning<
"invalid iOS deployment version '%0', iOS 10 is the maximum deployment "
"target for 32-bit targets">, InGroup<InvalidIOSDeploymentTarget>,
DefaultError;
def err_invalid_macos_32bit_deployment_target : Error<
"32-bit targets are not supported when building for Mac Catalyst">;
def err_drv_conflicting_deployment_targets : Error<
"conflicting deployment targets, both '%0' and '%1' are present in environment">;
def err_arc_unsupported_on_runtime : Error<
Expand Down
15 changes: 15 additions & 0 deletions clang/include/clang/Driver/DarwinSDKInfo.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#define LLVM_CLANG_DRIVER_DARWIN_SDK_INFO_H

#include "clang/Basic/LLVM.h"
#include "llvm/ADT/StringMap.h"
#include "llvm/Support/Error.h"
#include "llvm/Support/VersionTuple.h"
#include "llvm/Support/VirtualFileSystem.h"
Expand All @@ -20,12 +21,26 @@ namespace driver {
/// The information about the darwin SDK that was used during this compilation.
class DarwinSDKInfo {
public:
/// Represents the mapping between macOS and IosMac versions.
class IOSMacVersionMapping {
public:
VersionTuple getiOSMacVersionForMacOSVersion();

llvm::StringMap<VersionTuple> MacOS2iOSMacMapping;
llvm::StringMap<VersionTuple> IosMac2macOSMapping;
};

DarwinSDKInfo(llvm::VersionTuple Version) : Version(Version) {}

const llvm::VersionTuple &getVersion() const { return Version; }

IOSMacVersionMapping &getVersionMap() { return VersionMap; }

const IOSMacVersionMapping &getVersionMap() const { return VersionMap; }

private:
llvm::VersionTuple Version;
IOSMacVersionMapping VersionMap;
};

/// Parse the SDK information from the SDKSettings.json file.
Expand Down
44 changes: 38 additions & 6 deletions clang/lib/Driver/DarwinSDKInfo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,42 @@
using namespace clang::driver;
using namespace clang;

static Optional<DarwinSDKInfo>
parseDarwinSDKSettingsJSON(const llvm::json::Object *Obj) {
auto VersionString = Obj->getString("Version");
if (!VersionString)
return None;
VersionTuple Version;
if (Version.tryParse(*VersionString))
return None;
DarwinSDKInfo SDKInfo(Version);
if (const auto *VM = Obj->getObject("VersionMap")) {
auto parseVersionMap = [](const llvm::json::Object &Obj,
llvm::StringMap<VersionTuple> &Mapping) -> bool {
for (const auto &KV : Obj) {
if (auto Val = KV.getSecond().getAsString()) {
llvm::VersionTuple Version;
if (Version.tryParse(*Val))
return true;
Mapping[KV.getFirst()] = Version;
}
}
return false;
};
if (const auto *Mapping = VM->getObject("macOS_iOSMac")) {
if (parseVersionMap(*Mapping,
SDKInfo.getVersionMap().MacOS2iOSMacMapping))
return None;
}
if (const auto *Mapping = VM->getObject("iOSMac_macOS")) {
if (parseVersionMap(*Mapping,
SDKInfo.getVersionMap().IosMac2macOSMapping))
return None;
}
}
return std::move(SDKInfo);
}

Expected<Optional<DarwinSDKInfo>>
driver::parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, StringRef SDKRootPath) {
llvm::SmallString<256> Filepath = SDKRootPath;
Expand All @@ -31,12 +67,8 @@ driver::parseDarwinSDKInfo(llvm::vfs::FileSystem &VFS, StringRef SDKRootPath) {
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);
}
if (auto SDKInfo = parseDarwinSDKSettingsJSON(Obj))
return std::move(SDKInfo);
}
return llvm::make_error<llvm::StringError>("invalid SDKSettings.json",
llvm::inconvertibleErrorCode());
Expand Down
Loading