Reuse existing functionality in XcodeSDK::SDKSupportsModules (NFC)
authorAdrian Prantl <aprantl@apple.com>
Thu, 7 May 2020 00:20:15 +0000 (17:20 -0700)
committerAdrian Prantl <aprantl@apple.com>
Thu, 7 May 2020 17:46:51 +0000 (10:46 -0700)
Differential Revision: https://reviews.llvm.org/D79533

lldb/source/Utility/XcodeSDK.cpp

index 197eef1..fc1fc32 100644 (file)
@@ -182,25 +182,11 @@ bool XcodeSDK::SDKSupportsModules(XcodeSDK::Type desired_type,
                                   const FileSpec &sdk_path) {
   ConstString last_path_component = sdk_path.GetLastPathComponent();
 
-  if (last_path_component) {
-    const llvm::StringRef sdk_name = last_path_component.GetStringRef();
-
-    const std::string sdk_name_lower = sdk_name.lower();
-    Info info;
-    info.type = desired_type;
-    const std::string sdk_string = GetCanonicalName(info);
-    if (!llvm::StringRef(sdk_name_lower).startswith(sdk_string))
-      return false;
-
-    auto version_part = sdk_name.drop_front(sdk_string.size());
-    version_part.consume_back(".sdk");
-    version_part.consume_back(".Internal");
-
-    llvm::VersionTuple version;
-    if (version.tryParse(version_part))
-      return false;
-    return SDKSupportsModules(desired_type, version);
-  }
+  if (!last_path_component)
+    return false;
 
-  return false;
+  XcodeSDK sdk(last_path_component.GetStringRef().str());
+  if (sdk.GetType() != desired_type)
+    return false;
+  return SDKSupportsModules(sdk.GetType(), sdk.GetVersion());
 }