@@ -1690,6 +1690,15 @@ getDeploymentTargetFromEnvironmentVariables(const Driver &TheDriver,
1690
1690
return None;
1691
1691
}
1692
1692
1693
+ // / Returns the SDK name without the optional prefix that ends with a '.' or an
1694
+ // / empty string otherwise.
1695
+ static StringRef dropSDKNamePrefix (StringRef SDKName) {
1696
+ size_t PrefixPos = SDKName.find (' .' );
1697
+ if (PrefixPos == StringRef::npos)
1698
+ return " " ;
1699
+ return SDKName.substr (PrefixPos + 1 );
1700
+ }
1701
+
1693
1702
// / Tries to infer the deployment target from the SDK specified by -isysroot
1694
1703
// / (or SDKROOT). Uses the version specified in the SDKSettings.json file if
1695
1704
// / it's available.
@@ -1719,22 +1728,29 @@ inferDeploymentTargetFromSDK(DerivedArgList &Args,
1719
1728
if (Version.empty ())
1720
1729
return None;
1721
1730
1722
- if (SDK.startswith (" iPhoneOS" ) || SDK.startswith (" iPhoneSimulator" ))
1723
- return DarwinPlatform::createFromSDK (
1724
- Darwin::IPhoneOS, Version,
1725
- /* IsSimulator=*/ SDK.startswith (" iPhoneSimulator" ));
1726
- else if (SDK.startswith (" MacOSX" ))
1727
- return DarwinPlatform::createFromSDK (Darwin::MacOS,
1728
- getSystemOrSDKMacOSVersion (Version));
1729
- else if (SDK.startswith (" WatchOS" ) || SDK.startswith (" WatchSimulator" ))
1730
- return DarwinPlatform::createFromSDK (
1731
- Darwin::WatchOS, Version,
1732
- /* IsSimulator=*/ SDK.startswith (" WatchSimulator" ));
1733
- else if (SDK.startswith (" AppleTVOS" ) || SDK.startswith (" AppleTVSimulator" ))
1734
- return DarwinPlatform::createFromSDK (
1735
- Darwin::TvOS, Version,
1736
- /* IsSimulator=*/ SDK.startswith (" AppleTVSimulator" ));
1737
- return None;
1731
+ auto CreatePlatformFromSDKName =
1732
+ [&](StringRef SDK) -> Optional<DarwinPlatform> {
1733
+ if (SDK.startswith (" iPhoneOS" ) || SDK.startswith (" iPhoneSimulator" ))
1734
+ return DarwinPlatform::createFromSDK (
1735
+ Darwin::IPhoneOS, Version,
1736
+ /* IsSimulator=*/ SDK.startswith (" iPhoneSimulator" ));
1737
+ else if (SDK.startswith (" MacOSX" ))
1738
+ return DarwinPlatform::createFromSDK (Darwin::MacOS,
1739
+ getSystemOrSDKMacOSVersion (Version));
1740
+ else if (SDK.startswith (" WatchOS" ) || SDK.startswith (" WatchSimulator" ))
1741
+ return DarwinPlatform::createFromSDK (
1742
+ Darwin::WatchOS, Version,
1743
+ /* IsSimulator=*/ SDK.startswith (" WatchSimulator" ));
1744
+ else if (SDK.startswith (" AppleTVOS" ) || SDK.startswith (" AppleTVSimulator" ))
1745
+ return DarwinPlatform::createFromSDK (
1746
+ Darwin::TvOS, Version,
1747
+ /* IsSimulator=*/ SDK.startswith (" AppleTVSimulator" ));
1748
+ return None;
1749
+ };
1750
+ if (auto Result = CreatePlatformFromSDKName (SDK))
1751
+ return Result;
1752
+ // The SDK can be an SDK variant with a name like `<prefix>.<platform>`.
1753
+ return CreatePlatformFromSDKName (dropSDKNamePrefix (SDK));
1738
1754
}
1739
1755
1740
1756
std::string getOSVersion (llvm::Triple::OSType OS, const llvm::Triple &Triple,
@@ -2000,7 +2016,9 @@ void Darwin::AddDeploymentTarget(DerivedArgList &Args) const {
2000
2016
StringRef SDKName = SDK.slice (0 , StartVer);
2001
2017
// Don't warn about the macabi SDK.
2002
2018
// FIXME: Can we warn here?
2003
- if (!SDKName.startswith (getPlatformFamily ()) && Environment != MacABI)
2019
+ if (!SDKName.startswith (getPlatformFamily ()) &&
2020
+ !dropSDKNamePrefix (SDKName).startswith (getPlatformFamily ())
2021
+ && Environment != MacABI)
2004
2022
getDriver ().Diag (diag::warn_incompatible_sysroot)
2005
2023
<< SDKName << getPlatformFamily ();
2006
2024
}
0 commit comments