Skip to content

Commit 9951578

Browse files
committed
Don't search for sim SDK path until we know we need it
When iterating over all Platforms looking for the best one, on a Mac the Simulator platforms (iOS, tvOS, watchOS) will first find their SDK directory by calling xcrun, then decide if they should activate or not. When that SDK is absent, the call to xcrun to find it can be very slow. This patch delays that directory search until we know we're activating this platform, so non-simulator environments don't pay a perf cost ever time they go through the list of platforms. Differential Revision: https://reviews.llvm.org/D122373 rdar://87960090
1 parent 8e9c7f7 commit 9951578

File tree

3 files changed

+25
-18
lines changed

3 files changed

+25
-18
lines changed

lldb/source/Host/macosx/objcxx/HostInfoMacOSX.mm

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -379,6 +379,13 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
379379
args.AppendArgument("--sdk");
380380
args.AppendArgument(sdk);
381381

382+
Log *log = GetLog(LLDBLog::Host);
383+
if (log) {
384+
std::string cmdstr;
385+
args.GetCommandString(cmdstr);
386+
log->Printf("GetXcodeSDK() running shell cmd '%s'", cmdstr.c_str());
387+
}
388+
382389
int status = 0;
383390
int signo = 0;
384391
std::string output_str;

lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.cpp

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -274,13 +274,23 @@ std::vector<ArchSpec> PlatformAppleSimulator::GetSupportedArchitectures(
274274
return result;
275275
}
276276

277+
static llvm::StringRef GetXcodeSDKDir(std::string preferred,
278+
std::string secondary) {
279+
llvm::StringRef sdk;
280+
sdk = HostInfo::GetXcodeSDKPath(XcodeSDK(std::move(preferred)));
281+
if (sdk.empty())
282+
sdk = HostInfo::GetXcodeSDKPath(XcodeSDK(std::move(secondary)));
283+
return sdk;
284+
}
285+
277286
PlatformSP PlatformAppleSimulator::CreateInstance(
278287
const char *class_name, const char *description, ConstString plugin_name,
279288
llvm::SmallVector<llvm::Triple::ArchType, 4> supported_arch,
280289
llvm::Triple::OSType preferred_os,
281290
llvm::SmallVector<llvm::Triple::OSType, 4> supported_os,
282291
llvm::SmallVector<llvm::StringRef, 4> supported_triples,
283-
llvm::StringRef sdk, lldb_private::XcodeSDK::Type sdk_type,
292+
std::string sdk_name_preferred, std::string sdk_name_secondary,
293+
lldb_private::XcodeSDK::Type sdk_type,
284294
CoreSimulatorSupport::DeviceType::ProductFamilyID kind, bool force,
285295
const ArchSpec *arch) {
286296
Log *log = GetLog(LLDBLog::Platform);
@@ -338,6 +348,8 @@ PlatformSP PlatformAppleSimulator::CreateInstance(
338348
if (create) {
339349
LLDB_LOGF(log, "%s::%s() creating platform", class_name, __FUNCTION__);
340350

351+
llvm::StringRef sdk =
352+
GetXcodeSDKDir(sdk_name_preferred, sdk_name_secondary);
341353
return PlatformSP(new PlatformAppleSimulator(
342354
class_name, description, plugin_name, preferred_os, supported_triples,
343355
sdk, sdk_type, kind));
@@ -514,15 +526,6 @@ static bool shouldSkipSimulatorPlatform(bool force, const ArchSpec *arch) {
514526
!arch->TripleEnvironmentWasSpecified();
515527
}
516528

517-
static llvm::StringRef GetXcodeSDKDir(std::string preferred,
518-
std::string secondary) {
519-
llvm::StringRef sdk;
520-
sdk = HostInfo::GetXcodeSDKPath(XcodeSDK(std::move(preferred)));
521-
if (sdk.empty())
522-
sdk = HostInfo::GetXcodeSDKPath(XcodeSDK(std::move(secondary)));
523-
return sdk;
524-
}
525-
526529
static const char *g_ios_plugin_name = "ios-simulator";
527530
static const char *g_ios_description = "iPhone simulator platform plug-in.";
528531

@@ -540,10 +543,6 @@ struct PlatformiOSSimulator {
540543
static PlatformSP CreateInstance(bool force, const ArchSpec *arch) {
541544
if (shouldSkipSimulatorPlatform(force, arch))
542545
return nullptr;
543-
llvm::StringRef sdk;
544-
sdk = HostInfo::GetXcodeSDKPath(XcodeSDK("iPhoneSimulator.Internal.sdk"));
545-
if (sdk.empty())
546-
sdk = HostInfo::GetXcodeSDKPath(XcodeSDK("iPhoneSimulator.sdk"));
547546

548547
return PlatformAppleSimulator::CreateInstance(
549548
"PlatformiOSSimulator", g_ios_description,
@@ -566,7 +565,7 @@ struct PlatformiOSSimulator {
566565
#endif
567566
#endif
568567
},
569-
GetXcodeSDKDir("iPhoneSimulator.Internal.sdk", "iPhoneSimulator.sdk"),
568+
"iPhoneSimulator.Internal.sdk", "iPhoneSimulator.sdk",
570569
XcodeSDK::Type::iPhoneSimulator,
571570
CoreSimulatorSupport::DeviceType::ProductFamilyID::iPhone, force, arch);
572571
}
@@ -604,7 +603,7 @@ struct PlatformAppleTVSimulator {
604603
#endif
605604
#endif
606605
},
607-
GetXcodeSDKDir("AppleTVSimulator.Internal.sdk", "AppleTVSimulator.sdk"),
606+
"AppleTVSimulator.Internal.sdk", "AppleTVSimulator.sdk",
608607
XcodeSDK::Type::AppleTVSimulator,
609608
CoreSimulatorSupport::DeviceType::ProductFamilyID::appleTV, force,
610609
arch);
@@ -646,7 +645,7 @@ struct PlatformAppleWatchSimulator {
646645
#endif
647646
#endif
648647
},
649-
GetXcodeSDKDir("WatchSimulator.Internal.sdk", "WatchSimulator.sdk"),
648+
"WatchSimulator.Internal.sdk", "WatchSimulator.sdk",
650649
XcodeSDK::Type::WatchSimulator,
651650
CoreSimulatorSupport::DeviceType::ProductFamilyID::appleWatch, force,
652651
arch);

lldb/source/Plugins/Platform/MacOSX/PlatformAppleSimulator.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ class PlatformAppleSimulator : public PlatformDarwin {
5959
llvm::Triple::OSType preferred_os,
6060
llvm::SmallVector<llvm::Triple::OSType, 4> supported_os,
6161
llvm::SmallVector<llvm::StringRef, 4> supported_triples,
62-
llvm::StringRef sdk, XcodeSDK::Type sdk_type,
62+
std::string sdk_name_preferred, std::string sdk_name_secondary,
63+
XcodeSDK::Type sdk_type,
6364
CoreSimulatorSupport::DeviceType::ProductFamilyID kind,
6465
bool force, const ArchSpec *arch);
6566

0 commit comments

Comments
 (0)