Skip to content

Commit 3b48963

Browse files
committed
Check if resource directory exists in -sdk and fall back to default if not
1 parent cdfeadf commit 3b48963

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@
2424
WARNING(warning_no_such_sdk,none,
2525
"no such SDK: '%0'", (StringRef))
2626

27+
WARNING(warning_no_resource_dir_in_sdk, none,
28+
" You passed in an external -sdk without a Swift runtime.\n"
29+
" Either specify a directory containing the runtime libraries with\n"
30+
" the -resource-dir flag, or use -sysroot instead to point at a C/C++\n"
31+
" sysroot alone. Falling back to this path for the Swift runtime modules\n"
32+
" and libraries:\n"
33+
" %0", (StringRef))
2734
ERROR(error_no_frontend_args, none,
2835
"no arguments provided to '-frontend'", ())
2936

lib/Frontend/CompilerInvocation.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2421,7 +2421,12 @@ static bool ParseSearchPathArgs(SearchPathOptions &Opts, ArgList &Args,
24212421
llvm::sys::path::append(
24222422
SDKResourcePath, "usr", "lib",
24232423
FrontendOpts.UseSharedResourceFolder ? "swift" : "swift_static");
2424-
Opts.RuntimeResourcePath = SDKResourcePath.str();
2424+
// Check for eg <sdkRoot>/usr/lib/swift/
2425+
if (llvm::sys::fs::exists(SDKResourcePath))
2426+
Opts.RuntimeResourcePath = SDKResourcePath.str();
2427+
else
2428+
Diags.diagnose(SourceLoc(), diag::warning_no_resource_dir_in_sdk,
2429+
Opts.RuntimeResourcePath);
24252430
}
24262431

24272432
Opts.SkipAllImplicitImportPaths |= Args.hasArg(OPT_nostdimport);

0 commit comments

Comments
 (0)