diff options
Diffstat (limited to 'clang/lib')
-rw-r--r-- | clang/lib/Driver/ToolChains.cpp | 48 | ||||
-rw-r--r-- | clang/lib/Driver/ToolChains.h | 2 |
2 files changed, 45 insertions, 5 deletions
diff --git a/clang/lib/Driver/ToolChains.cpp b/clang/lib/Driver/ToolChains.cpp index f02b5fb0b9e..f905b5db503 100644 --- a/clang/lib/Driver/ToolChains.cpp +++ b/clang/lib/Driver/ToolChains.cpp @@ -329,6 +329,36 @@ void MachO::AddLinkRuntimeLib(const ArgList &Args, ArgStringList &CmdArgs, } } +StringRef Darwin::getPlatformFamily() const { + switch (TargetPlatform) { + case DarwinPlatformKind::MacOS: + return "MacOSX"; + case DarwinPlatformKind::IPhoneOS: + case DarwinPlatformKind::IPhoneOSSimulator: + return "iPhone"; + case DarwinPlatformKind::TvOS: + case DarwinPlatformKind::TvOSSimulator: + return "AppleTV"; + case DarwinPlatformKind::WatchOS: + case DarwinPlatformKind::WatchOSSimulator: + return "Watch"; + } + llvm_unreachable("Unsupported platform"); +} + +StringRef Darwin::getSDKName(StringRef isysroot) { + // Assume SDK has path: SOME_PATH/SDKs/PlatformXX.YY.sdk + llvm::sys::path::const_iterator SDKDir; + auto BeginSDK = llvm::sys::path::begin(isysroot); + auto EndSDK = llvm::sys::path::end(isysroot); + for (auto IT = BeginSDK; IT != EndSDK; ++IT) { + StringRef SDK = *IT; + if (SDK.endswith(".sdk")) + return SDK.slice(0, SDK.size() - 4); + } + return ""; +} + StringRef Darwin::getOSLibraryNameSuffix() const { switch(TargetPlatform) { case DarwinPlatformKind::MacOS: @@ -540,11 +570,8 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { TvOSTarget.empty() && Args.hasArg(options::OPT_isysroot)) { if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { StringRef isysroot = A->getValue(); - // Assume SDK has path: SOME_PATH/SDKs/PlatformXX.YY.sdk - size_t BeginSDK = isysroot.rfind("SDKs/"); - size_t EndSDK = isysroot.rfind(".sdk"); - if (BeginSDK != StringRef::npos && EndSDK != StringRef::npos) { - StringRef SDK = isysroot.slice(BeginSDK + 5, EndSDK); + StringRef SDK = getSDKName(isysroot); + if (SDK.size() > 0) { // Slice the version number out. // Version number is between the first and the last number. size_t StartVer = SDK.find_first_of("0123456789"); @@ -697,6 +724,17 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { Platform = WatchOSSimulator; setTarget(Platform, Major, Minor, Micro); + + if (const Arg *A = Args.getLastArg(options::OPT_isysroot)) { + StringRef SDK = getSDKName(A->getValue()); + if (SDK.size() > 0) { + size_t StartVer = SDK.find_first_of("0123456789"); + StringRef SDKName = SDK.slice(0, StartVer); + if (!SDKName.startswith(getPlatformFamily())) + getDriver().Diag(diag::warn_incompatible_sysroot) + << SDKName << getPlatformFamily(); + } + } } void DarwinClang::AddCXXStdlibLibArgs(const ArgList &Args, diff --git a/clang/lib/Driver/ToolChains.h b/clang/lib/Driver/ToolChains.h index e7992170cc8..9a08d8e7d5f 100644 --- a/clang/lib/Driver/ToolChains.h +++ b/clang/lib/Driver/ToolChains.h @@ -496,6 +496,8 @@ protected: return TargetVersion < VersionTuple(V0, V1, V2); } + StringRef getPlatformFamily() const; + static StringRef getSDKName(StringRef isysroot); StringRef getOSLibraryNameSuffix() const; public: |