Author: Alex Lorenz Date: 2021-03-09T14:57:58-08:00 New Revision: 234f3211a3dd84bb2c074402054452af24b914a6
URL: https://github.com/llvm/llvm-project/commit/234f3211a3dd84bb2c074402054452af24b914a6 DIFF: https://github.com/llvm/llvm-project/commit/234f3211a3dd84bb2c074402054452af24b914a6.diff LOG: [clang][driver] Support Darwin SDK names with an optional prefix in their name rdar://74017977 Added: clang/test/Driver/darwin-sdk-with-prefix.c Modified: clang/lib/Driver/ToolChains/Darwin.cpp Removed: ################################################################################ diff --git a/clang/lib/Driver/ToolChains/Darwin.cpp b/clang/lib/Driver/ToolChains/Darwin.cpp index 91241ff9bd81..a09a69f946ef 100644 --- a/clang/lib/Driver/ToolChains/Darwin.cpp +++ b/clang/lib/Driver/ToolChains/Darwin.cpp @@ -1628,6 +1628,15 @@ getDeploymentTargetFromEnvironmentVariables(const Driver &TheDriver, return None; } +/// Returns the SDK name without the optional prefix that ends with a '.' or an +/// empty string otherwise. +static StringRef dropSDKNamePrefix(StringRef SDKName) { + size_t PrefixPos = SDKName.find('.'); + if (PrefixPos == StringRef::npos) + return ""; + return SDKName.substr(PrefixPos + 1); +} + /// Tries to infer the deployment target from the SDK specified by -isysroot /// (or SDKROOT). Uses the version specified in the SDKSettings.json file if /// it's available. @@ -1657,22 +1666,29 @@ inferDeploymentTargetFromSDK(DerivedArgList &Args, if (Version.empty()) return None; - if (SDK.startswith("iPhoneOS") || SDK.startswith("iPhoneSimulator")) - return DarwinPlatform::createFromSDK( - Darwin::IPhoneOS, Version, - /*IsSimulator=*/SDK.startswith("iPhoneSimulator")); - else if (SDK.startswith("MacOSX")) - return DarwinPlatform::createFromSDK(Darwin::MacOS, - getSystemOrSDKMacOSVersion(Version)); - else if (SDK.startswith("WatchOS") || SDK.startswith("WatchSimulator")) - return DarwinPlatform::createFromSDK( - Darwin::WatchOS, Version, - /*IsSimulator=*/SDK.startswith("WatchSimulator")); - else if (SDK.startswith("AppleTVOS") || SDK.startswith("AppleTVSimulator")) - return DarwinPlatform::createFromSDK( - Darwin::TvOS, Version, - /*IsSimulator=*/SDK.startswith("AppleTVSimulator")); - return None; + auto CreatePlatformFromSDKName = + [&](StringRef SDK) -> Optional<DarwinPlatform> { + if (SDK.startswith("iPhoneOS") || SDK.startswith("iPhoneSimulator")) + return DarwinPlatform::createFromSDK( + Darwin::IPhoneOS, Version, + /*IsSimulator=*/SDK.startswith("iPhoneSimulator")); + else if (SDK.startswith("MacOSX")) + return DarwinPlatform::createFromSDK(Darwin::MacOS, + getSystemOrSDKMacOSVersion(Version)); + else if (SDK.startswith("WatchOS") || SDK.startswith("WatchSimulator")) + return DarwinPlatform::createFromSDK( + Darwin::WatchOS, Version, + /*IsSimulator=*/SDK.startswith("WatchSimulator")); + else if (SDK.startswith("AppleTVOS") || SDK.startswith("AppleTVSimulator")) + return DarwinPlatform::createFromSDK( + Darwin::TvOS, Version, + /*IsSimulator=*/SDK.startswith("AppleTVSimulator")); + return None; + }; + if (auto Result = CreatePlatformFromSDKName(SDK)) + return Result; + // The SDK can be an SDK variant with a name like `<prefix>.<platform>`. + return CreatePlatformFromSDKName(dropSDKNamePrefix(SDK)); } std::string getOSVersion(llvm::Triple::OSType OS, const llvm::Triple &Triple, @@ -1928,7 +1944,8 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const { if (SDK.size() > 0) { size_t StartVer = SDK.find_first_of("0123456789"); StringRef SDKName = SDK.slice(0, StartVer); - if (!SDKName.startswith(getPlatformFamily())) + if (!SDKName.startswith(getPlatformFamily()) && + !dropSDKNamePrefix(SDKName).startswith(getPlatformFamily())) getDriver().Diag(diag::warn_incompatible_sysroot) << SDKName << getPlatformFamily(); } diff --git a/clang/test/Driver/darwin-sdk-with-prefix.c b/clang/test/Driver/darwin-sdk-with-prefix.c new file mode 100644 index 000000000000..7619ded56b65 --- /dev/null +++ b/clang/test/Driver/darwin-sdk-with-prefix.c @@ -0,0 +1,10 @@ +// RUN: rm -rf %t.dir +// RUN: mkdir -p %t.dir + +// RUN: rm -rf %t.dir/prefix.iPhoneOS12.0.0.sdk +// RUN: mkdir -p %t.dir/prefix.iPhoneOS12.0.0.sdk +// RUN: %clang -c -isysroot %t.dir/prefix.iPhoneOS12.0.0.sdk -target arm64-apple-darwin %s -### 2>&1 | FileCheck %s +// RUN: env SDKROOT=%t.dir/prefix.iPhoneOS12.0.0.sdk %clang -c -target arm64-apple-darwin %s -### 2>&1 | FileCheck %s +// +// CHECK-NOT: warning: using sysroot for +// CHECK: "-triple" "arm64-apple-ios12.0.0" _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits