@@ -373,26 +373,19 @@ static void ParseOSVersion(llvm::VersionTuple &version, NSString *Key) {
373
373
static std::string GetXcodeSDK (XcodeSDK sdk) {
374
374
XcodeSDK::Info info = sdk.Parse ();
375
375
std::string sdk_name = XcodeSDK::GetCanonicalName (info);
376
- auto find_sdk = [](std::string sdk_name) -> std::string {
377
- std::string xcrun_cmd;
378
- std::string developer_dir = GetEnvDeveloperDir ();
379
- if (developer_dir.empty ())
380
- if (FileSpec fspec = HostInfo::GetShlibDir ())
381
- if (FileSystem::Instance ().Exists (fspec)) {
382
- FileSpec path (
383
- XcodeSDK::FindXcodeContentsDirectoryInPath (fspec.GetPath ()));
384
- if (path.RemoveLastPathComponent ())
385
- developer_dir = path.GetPath ();
386
- }
376
+
377
+ auto xcrun = [](const std::string &sdk,
378
+ llvm::StringRef developer_dir = " " ) -> std::string {
379
+ std::string xcrun_cmd = " xcrun --show-sdk-path --sdk " + sdk;
387
380
if (!developer_dir.empty ())
388
- xcrun_cmd = " /usr/bin/env DEVELOPER_DIR=\" " + developer_dir + " \" " ;
389
- xcrun_cmd += " xcrun --show-sdk-path --sdk " + sdk_name ;
381
+ xcrun_cmd = " /usr/bin/env DEVELOPER_DIR=\" " + developer_dir. str () +
382
+ " \" " + xcrun_cmd ;
390
383
391
384
int status = 0 ;
392
385
int signo = 0 ;
393
386
std::string output_str;
394
387
lldb_private::Status error =
395
- Host::RunShellCommand (xcrun_cmd. c_str () , FileSpec (), &status, &signo,
388
+ Host::RunShellCommand (xcrun_cmd, FileSpec (), &status, &signo,
396
389
&output_str, std::chrono::seconds (15 ));
397
390
398
391
// Check that xcrun return something useful.
@@ -414,6 +407,33 @@ FileSpec path(
414
407
return output.str ();
415
408
};
416
409
410
+ auto find_sdk = [&xcrun](const std::string &sdk_name) -> std::string {
411
+ // Invoke xcrun with the developer dir specified in the environment.
412
+ std::string developer_dir = GetEnvDeveloperDir ();
413
+ if (!developer_dir.empty ()) {
414
+ // Don't fallback if DEVELOPER_DIR was set.
415
+ return xcrun (sdk_name, developer_dir);
416
+ }
417
+
418
+ // Invoke xcrun with the shlib dir.
419
+ if (FileSpec fspec = HostInfo::GetShlibDir ()) {
420
+ if (FileSystem::Instance ().Exists (fspec)) {
421
+ std::string contents_dir =
422
+ XcodeSDK::FindXcodeContentsDirectoryInPath (fspec.GetPath ());
423
+ llvm::StringRef shlib_developer_dir =
424
+ llvm::sys::path::parent_path (contents_dir);
425
+ if (!shlib_developer_dir.empty ()) {
426
+ std::string sdk = xcrun (sdk_name, std::move (shlib_developer_dir));
427
+ if (!sdk.empty ())
428
+ return sdk;
429
+ }
430
+ }
431
+ }
432
+
433
+ // Invoke xcrun without a developer dir as a last resort.
434
+ return xcrun (sdk_name);
435
+ };
436
+
417
437
std::string path = find_sdk (sdk_name);
418
438
while (path.empty ()) {
419
439
// Try an alternate spelling of the name ("macosx10.9internal").
0 commit comments